Skip to content

Commit 71b9811

Browse files
committed
minor #6050 Lots of minor fixes & applying best practices to form cookbook doc (ThomasLandauer, WouterJ)
This PR was merged into the 2.3 branch. Discussion ---------- Lots of minor fixes & applying best practices to form cookbook doc This finishes #5569 | Q | A | --- | --- | doc fix? | yes | New docs? | no | Applies to | 2.3+ | Fixed tickets | - Commits ------- 99cdc00 Revert some changes and fix template names 2b00abe Minor clarification 3ce46f6 Fixed file path d227ffb Fixed typo 44d19de Added example for 'required' => false ebb1e74 Update templating.rst d806300 Typo: Removed comma 6e41f57 Another typo a4f0318 Fixed typo 275c079 Removed unnecessary(?) YAML hint 9cd391b Note about nesting blocks and {% endblock NAME %} 41f7e6f Changed <meta http-equiv> to HTML5's <meta charset>
2 parents 3640b2a + 99cdc00 commit 71b9811

File tree

4 files changed

+49
-34
lines changed

4 files changed

+49
-34
lines changed

book/doctrine.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -953,8 +953,8 @@ To relate the ``Category`` and ``Product`` entities, start by creating a
953953
products:
954954
targetEntity: Product
955955
mappedBy: category
956-
# don't forget to init the collection in the __construct() method
957-
# of the entity
956+
# Don't forget to initialize the collection in
957+
# the __construct() method of the entity
958958
959959
.. code-block:: xml
960960
@@ -1096,7 +1096,7 @@ table, and ``product.category_id`` column, and new foreign key:
10961096
10971097
.. note::
10981098

1099-
This task should only be really used during development. For a more robust
1099+
This command should only be used during development. For a more robust
11001100
method of systematically updating your production database, read about
11011101
`migrations`_.
11021102

@@ -1187,7 +1187,7 @@ You can also query in the other direction::
11871187
// ...
11881188
}
11891189

1190-
In this case, the same things occurs: you first query out for a single ``Category``
1190+
In this case, the same things occur: you first query out for a single ``Category``
11911191
object, and then Doctrine makes a second query to retrieve the related ``Product``
11921192
objects, but only once/if you ask for them (i.e. when you call ``->getProducts()``).
11931193
The ``$products`` variable is an array of all ``Product`` objects that relate

book/forms.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ Handling Form Submissions
212212

213213
The second job of a form is to translate user-submitted data back to the
214214
properties of an object. To make this happen, the submitted data from the
215-
user must be written into the form. Add the following functionality to your
216-
controller::
215+
user must be written into the Form object. Add the following functionality to
216+
your controller::
217217

218218
// ...
219219
use Symfony\Component\HttpFoundation\Request;
@@ -679,9 +679,14 @@ the documentation for each type.
679679
The most common option is the ``required`` option, which can be applied to
680680
any field. By default, the ``required`` option is set to ``true``, meaning
681681
that HTML5-ready browsers will apply client-side validation if the field
682-
is left blank. If you don't want this behavior, either set the ``required``
683-
option on your field to ``false`` or
684-
:ref:`disable HTML5 validation <book-forms-html5-validation-disable>`.
682+
is left blank. If you don't want this behavior, either
683+
:ref:`disable HTML5 validation <book-forms-html5-validation-disable>`
684+
or set the ``required`` option on your field to ``false``::
685+
686+
->add('dueDate', 'date', array(
687+
'widget' => 'single_text',
688+
'required' => false
689+
))
685690

686691
Also note that setting the ``required`` option to ``true`` will **not**
687692
result in server-side validation to be applied. In other words, if a
@@ -920,7 +925,7 @@ specify it:
920925

921926
Some field types have additional rendering options that can be passed
922927
to the widget. These options are documented with each type, but one common
923-
options is ``attr``, which allows you to modify attributes on the form element.
928+
option is ``attr``, which allows you to modify attributes on the form element.
924929
The following would add the ``task_field`` class to the rendered input text
925930
field:
926931

book/templating.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ First, build a base layout file:
201201
<!DOCTYPE html>
202202
<html>
203203
<head>
204-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
204+
<meta charset="UTF-8">
205205
<title>{% block title %}Test Application{% endblock %}</title>
206206
</head>
207207
<body>
@@ -226,7 +226,7 @@ First, build a base layout file:
226226
<!DOCTYPE html>
227227
<html>
228228
<head>
229-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
229+
<meta charset="UTF-8">
230230
<title><?php $view['slots']->output('title', 'Test Application') ?></title>
231231
</head>
232232
<body>
@@ -311,7 +311,7 @@ output might look like this:
311311
<!DOCTYPE html>
312312
<html>
313313
<head>
314-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
314+
<meta charset="UTF-8">
315315
<title>My cool blog posts</title>
316316
</head>
317317
<body>

cookbook/form/form_customization.rst

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ directly in the template that's actually rendering the form.
243243

244244
.. code-block:: html+twig
245245

246-
{% extends '::base.html.twig' %}
246+
{% extends 'base.html.twig' %}
247247

248248
{% form_theme form _self %}
249249

@@ -282,7 +282,7 @@ can now re-use the form customization across many templates:
282282

283283
.. code-block:: html+twig
284284

285-
{# app/Resources/views/Form/fields.html.twig #}
285+
{# app/Resources/views/form/fields.html.twig #}
286286
{% block integer_widget %}
287287
<div class="integer_widget">
288288
{% set type = type|default('number') %}
@@ -298,7 +298,7 @@ tell Symfony to use the template via the ``form_theme`` tag:
298298

299299
.. code-block:: html+twig
300300

301-
{% form_theme form 'AppBundle:Form:fields.html.twig' %}
301+
{% form_theme form 'form/fields.html.twig' %}
302302

303303
{{ form_widget(form.age) }}
304304

@@ -314,13 +314,12 @@ name of all the templates as an array using the ``with`` keyword:
314314

315315
.. code-block:: html+twig
316316

317-
{% form_theme form with ['::common.html.twig', ':Form:fields.html.twig',
318-
'AppBundle:Form:fields.html.twig'] %}
317+
{% form_theme form with ['common.html.twig', 'form/fields.html.twig'] %}
319318

320319
{# ... #}
321320

322-
The templates can be located at different bundles and they can even be stored
323-
at the global ``app/Resources/views/`` directory.
321+
The templates can also be located in different bundles, use the functional name
322+
to reference these templates, e.g. ``AcmeFormExtraBundle:form:fields.html.twig``.
324323

325324
Child Forms
326325
...........
@@ -329,16 +328,16 @@ You can also apply a form theme to a specific child of your form:
329328

330329
.. code-block:: html+twig
331330

332-
{% form_theme form.child 'AppBundle:Form:fields.html.twig' %}
331+
{% form_theme form.child 'form/fields.html.twig' %}
333332

334333
This is useful when you want to have a custom theme for a nested form that's
335334
different than the one of your main form. Just specify both your themes:
336335

337336
.. code-block:: html+twig
338337

339-
{% form_theme form 'AppBundle:Form:fields.html.twig' %}
338+
{% form_theme form 'form/fields.html.twig' %}
340339

341-
{% form_theme form.child 'AppBundle:Form:fields_child.html.twig' %}
340+
{% form_theme form.child 'form/fields_child.html.twig' %}
342341

343342
.. _cookbook-form-php-theming:
344343

@@ -354,9 +353,13 @@ file in order to customize the ``integer_widget`` fragment.
354353

355354
.. code-block:: html+php
356355

357-
<!-- app/Resources/views/Form/integer_widget.html.php -->
356+
<!-- app/Resources/views/form/integer_widget.html.php -->
358357
<div class="integer_widget">
359-
<?php echo $view['form']->block($form, 'form_widget_simple', array('type' => isset($type) ? $type : "number")) ?>
358+
<?php echo $view['form']->block(
359+
$form,
360+
'form_widget_simple',
361+
array('type' => isset($type) ? $type : "number")
362+
) ?>
360363
</div>
361364

362365
Now that you've created the customized form template, you need to tell Symfony
@@ -367,7 +370,7 @@ tell Symfony to use the theme via the ``setTheme`` helper method:
367370

368371
.. code-block:: php
369372
370-
<?php $view['form']->setTheme($form, array('AppBundle:Form')); ?>
373+
<?php $view['form']->setTheme($form, array(':form')); ?>
371374
372375
<?php $view['form']->widget($form['age']) ?>
373376
@@ -380,7 +383,14 @@ method:
380383

381384
.. code-block:: php
382385
383-
<?php $view['form']->setTheme($form['child'], 'AppBundle:Form/Child'); ?>
386+
<?php $view['form']->setTheme($form['child'], ':form'); ?>
387+
388+
.. note::
389+
390+
The ``:form`` syntax is based on the functional names for templates:
391+
``Bundle:Directory``. As the form directory lives in the
392+
``app/Resources/views`` directory, the ``Bundle`` part is empty, resulting
393+
in ``:form``.
384394

385395
.. _cookbook-form-twig-import-base-blocks:
386396

@@ -454,8 +464,8 @@ Twig
454464
~~~~
455465

456466
By using the following configuration, any customized form blocks inside the
457-
``AppBundle:Form:fields.html.twig`` template will be used globally when a
458-
form is rendered.
467+
``form/fields.html.twig`` template will be used globally when a form is
468+
rendered.
459469

460470
.. configuration-block::
461471

@@ -465,15 +475,15 @@ form is rendered.
465475
twig:
466476
form:
467477
resources:
468-
- 'AppBundle:Form:fields.html.twig'
478+
- 'form/fields.html.twig'
469479
# ...
470480
471481
.. code-block:: xml
472482
473483
<!-- app/config/config.xml -->
474484
<twig:config>
475485
<twig:form>
476-
<resource>AppBundle:Form:fields.html.twig</resource>
486+
<resource>form/fields.html.twig</resource>
477487
</twig:form>
478488
<!-- ... -->
479489
</twig:config>
@@ -484,7 +494,7 @@ form is rendered.
484494
$container->loadFromExtension('twig', array(
485495
'form' => array(
486496
'resources' => array(
487-
'AppBundle:Form:fields.html.twig',
497+
'form/fields.html.twig',
488498
),
489499
),
490500
@@ -666,7 +676,7 @@ customize the ``name`` field only:
666676
.. code-block:: html+php
667677

668678
<!-- Main template -->
669-
<?php echo $view['form']->setTheme($form, array('AppBundle:Form')); ?>
679+
<?php echo $view['form']->setTheme($form, array(':form')); ?>
670680

671681
<?php echo $view['form']->widget($form['name']); ?>
672682

@@ -723,7 +733,7 @@ You can also override the markup for an entire field row using the same method:
723733
.. code-block:: html+php
724734

725735
<!-- Main template -->
726-
<?php echo $view['form']->setTheme($form, array('AppBundle:Form')); ?>
736+
<?php echo $view['form']->setTheme($form, array(':form')); ?>
727737

728738
<?php echo $view['form']->row($form['name']); ?>
729739

0 commit comments

Comments
 (0)