Skip to content

Commit 4bb4475

Browse files
committed
[book][form] Proofreading new PHP form customization additions
1 parent 6761de4 commit 4bb4475

File tree

1 file changed

+33
-41
lines changed

1 file changed

+33
-41
lines changed

book/forms.rst

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -901,14 +901,15 @@ how each form "row" renders, change the markup used to render errors, or
901901
even customize how a textarea tag should be rendered. Nothing is off-limits,
902902
and different customizations can be used in different places.
903903

904-
Symfony uses templates to render each and every part of a form which are called
905-
fragments - a row, a textarea tag, errors, etc.
904+
Symfony uses templates to render each and every part of a form, such as
905+
field ``label`` tags, ``input`` tags, error messages and everything else.
906906

907-
In Twig, the fragments are represented by Twig "blocks". To customize any part
908-
of how a form renders, you just need to override the appropriate block.
907+
In Twig, each form "fragment" is represented by a Twig block. To customize
908+
any part of how a form renders, you just need to override the appropriate block.
909909

910-
In PHP, the fragments are individual template files. To customize any part of how
911-
a form renders, you just need to create a new template file.
910+
In PHP, each form "fragment" is rendered via an individual template file.
911+
To customize any part of how a form renders, you just need to override the
912+
existing template by creating a new one.
912913

913914
To understand how this works, let's customize the ``form_row`` fragment and
914915
add a class attribute to the ``div`` element that surrounds each row. To
@@ -940,9 +941,10 @@ do this, create a new template file that will store the new markup:
940941
<?php echo $view['form']->widget($form, $parameters) ?>
941942
</div>
942943

943-
The ``field_row`` fragment is used when rendering most fields via the ``form_row``
944-
function. To use the ``field_row`` fragment defined in this template, add the
945-
following to the top of the template that renders the form:
944+
The ``field_row`` form fragment is used when rendering most fields via the
945+
``form_row`` function. To tell the component to use your new ``field_row``
946+
fragment defined above, add the following to the top of the template that
947+
renders the form:
946948

947949
.. configuration-block:: php
948950

@@ -962,14 +964,14 @@ following to the top of the template that renders the form:
962964

963965
<form ...>
964966

965-
The ``form_theme`` tag "imports" the fragments defined in the theme and uses
966-
them when rendering the form. In other words, when ``form_row`` is called
967-
later in this template, it will use the ``field_row`` block from your custom
968-
theme.
967+
The ``form_theme`` tag (in Twig) "imports" the fragments defined in the given
968+
template and uses them when rendering the form. In other words, when ``form_row``
969+
is called later in this template, it will use the ``field_row`` block from
970+
your custom theme.
969971

970972
To customize any portion of a form, you just need to override the appropriate
971-
fragment. Knowing exactly which block to override is the subject of the next
972-
section.
973+
fragment. Knowing exactly which block or file to override is the subject of
974+
the next section.
973975

974976
In the following section, you'll learn more about how to customize different
975977
portions of a form. For a more extensive discussion, see :doc:`/cookbook/form/form_customization`.
@@ -979,17 +981,16 @@ portions of a form. For a more extensive discussion, see :doc:`/cookbook/form/fo
979981
Form Template Blocks
980982
~~~~~~~~~~~~~~~~~~~~
981983

982-
In Symfony, every fragment a form that is rendered - HTML form elements, errors,
983-
labels, etc - is defined in a base theme.
984-
985-
The fragments are defined as blocks in Twig and as template files in PHP.
984+
In Symfony, every part a form that is rendered - HTML form elements, errors,
985+
labels, etc - is defined in a base theme, which is a collection of blocks
986+
in Twig and a collection of template files in PHP.
986987

987988
In Twig, every block needed is defined in the `form_div_layout.html.twig`_ file
988989
that lives inside the `Twig Bridge`_. Inside this file, you can see every block
989990
needed to render a form and every default field type.
990991

991992
In PHP, the fragments are individual template files. By default they are located in
992-
the `FrameworkBundle/Resources/views/Form` folder.
993+
the `Resources/views/Form` directory of the framework bundle (`view on GitHub`_).
993994

994995
Each fragment name follows the same basic pattern and is broken up into two pieces,
995996
separated by a single underscore character (``_``). A few examples are:
@@ -1046,6 +1047,12 @@ override the default error rendering for *all* fields, copy and customize the
10461047
Global Form Theming
10471048
~~~~~~~~~~~~~~~~~~~
10481049

1050+
In addition to *theming* individual templates, you can also tell Symfony
1051+
to import form customizations across your entire project.
1052+
1053+
Twig
1054+
....
1055+
10491056
When using Twig, you've seen how you can use the ``form_theme`` Twig tag in a
10501057
template to import form customizations that will be used inside that template.
10511058
You can also tell Symfony to automatically use certain form customizations for
@@ -1062,7 +1069,6 @@ configuration file:
10621069
twig:
10631070
form:
10641071
resources:
1065-
- 'form_div_layout.html.twig'
10661072
- 'AcmeStoreBundle:Form:fields.html.twig'
10671073
# ...
10681074
@@ -1072,7 +1078,6 @@ configuration file:
10721078
10731079
<twig:config ...>
10741080
<twig:form>
1075-
<resource>form_div_layout.html.twig</resource>
10761081
<resource>AcmeStoreBundle:Form:fields.html.twig</resource>
10771082
</twig:form>
10781083
<!-- ... -->
@@ -1084,7 +1089,6 @@ configuration file:
10841089
10851090
$container->loadFromExtension('twig', array(
10861091
'form' => array('resources' => array(
1087-
'form_div_layout.html.twig',
10881092
'AcmeStoreBundle:Form:fields.html.twig',
10891093
))
10901094
// ...
@@ -1093,12 +1097,6 @@ configuration file:
10931097
Any blocks inside the ``fields.html.twig`` template are now used globally
10941098
to define form output.
10951099

1096-
.. note::
1097-
1098-
The `form_div_layout.html.twig`_ theme is automatically added as a default
1099-
when it is not provided in the list of resources. It would not have been
1100-
necessary to provide it in the examples above.
1101-
11021100
.. sidebar:: Customizing Form Output all in a Single File in Twig
11031101

11041102
You can also customize a form block right inside the template where that
@@ -1138,11 +1136,14 @@ to define form output.
11381136
</div>
11391137
{% endblock %}
11401138

1139+
PHP
1140+
...
1141+
11411142
When using PHP, you've seen how you can use the ``setTheme`` helper method in a
11421143
template to import form customizations that will be used inside that template.
11431144
You can also tell Symfony to automatically use certain form customizations for all
11441145
templates in your application. To automatically include the customized templates
1145-
from the `Acme/StoreBundle/Resources/views/Form` folder created earlier, modify
1146+
from the `Acme/StoreBundle/Resources/views/Form` directroy created earlier, modify
11461147
your application configuration file:
11471148

11481149
.. configuration-block::
@@ -1155,7 +1156,6 @@ your application configuration file:
11551156
templating:
11561157
form:
11571158
resources:
1158-
- 'FrameworkBundle:Form'
11591159
- 'AcmeStoreBundle:Form'
11601160
# ...
11611161
@@ -1167,7 +1167,6 @@ your application configuration file:
11671167
<framework:config ...>
11681168
<framework:templating>
11691169
<framework:form>
1170-
<resource>FrameworkBundle:Form</resource>
11711170
<resource>AcmeStoreBundle:Form</resource>
11721171
</framework:form>
11731172
</framework:templating>
@@ -1181,21 +1180,14 @@ your application configuration file:
11811180
$container->loadFromExtension('framework', array(
11821181
'templating' => array('form' =>
11831182
array('resources' => array(
1184-
'FrameworkBundle:Form',
11851183
'AcmeStoreBundle:Form',
11861184
)))
11871185
// ...
11881186
));
11891187
1190-
Any framents inside the `Acme/StoreBundle/Resources/views/Form` folder are now
1188+
Any framgents inside the `Acme/StoreBundle/Resources/views/Form` folder are now
11911189
used globally to define form output.
11921190

1193-
.. note::
1194-
1195-
The `FrameworkBundle:Form`_ theme is automatically added as a default when
1196-
it is not provided in the list of resources. It would not have been necessary
1197-
to provide it in the examples above.
1198-
11991191
.. index::
12001192
single: Forms; CSRF Protection
12011193

@@ -1277,5 +1269,5 @@ Learn more from the Cookbook
12771269
.. _`Symfony2 Form Component`: https://github.com/symfony/Form
12781270
.. _`Twig Bridge`: https://github.com/symfony/symfony/tree/master/src/Symfony/Bridge/Twig
12791271
.. _`form_div_layout.html.twig`: https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
1280-
.. _`FrameworkBundle:Form`: https://github.com/symfony/symfony/tree/master/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form
12811272
.. _`Cross-site request forgery`: http://en.wikipedia.org/wiki/Cross-site_request_forgery
1273+
.. _`view on GitHub`: https://github.com/symfony/symfony/tree/master/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form

0 commit comments

Comments
 (0)