Skip to content

Commit a057523

Browse files
committed
[form] Updating latest form variables code for 2.1
Also updating some direct code links to 2.1
1 parent 09fda35 commit a057523

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

book/forms.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,6 @@ Learn more from the Cookbook
16141614
.. _`Symfony2 Form Component`: https://github.com/symfony/Form
16151615
.. _`DateTime`: http://php.net/manual/en/class.datetime.php
16161616
.. _`Twig Bridge`: https://github.com/symfony/symfony/tree/master/src/Symfony/Bridge/Twig
1617-
.. _`form_div_layout.html.twig`: https://github.com/symfony/symfony/blob/2.0/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
1617+
.. _`form_div_layout.html.twig`: https://github.com/symfony/symfony/blob/2.1/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
16181618
.. _`Cross-site request forgery`: http://en.wikipedia.org/wiki/Cross-site_request_forgery
16191619
.. _`view on GitHub`: https://github.com/symfony/symfony/tree/master/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form

cookbook/form/form_customization.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,4 +949,4 @@ customizations directly. Look at the following example:
949949
The array passed as the second argument contains form "variables". For
950950
more details about this concept in Twig, see :ref:`twig-reference-form-variables`.
951951

952-
.. _`form_div_layout.html.twig`: https://github.com/symfony/symfony/blob/2.0/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
952+
.. _`form_div_layout.html.twig`: https://github.com/symfony/symfony/blob/2.1/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

reference/dic_tags.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,5 +771,5 @@ For an example, see the ``EntityInitializer`` class inside the Doctrine Bridge.
771771

772772
.. _`Twig's documentation`: http://twig.sensiolabs.org/doc/advanced.html#creating-an-extension
773773
.. _`Twig official extension repository`: http://github.com/fabpot/Twig-extensions
774-
.. _`KernelEvents`: https://github.com/symfony/symfony/blob/2.0/src/Symfony/Component/HttpKernel/KernelEvents.php
774+
.. _`KernelEvents`: https://github.com/symfony/symfony/blob/2.1/src/Symfony/Component/HttpKernel/KernelEvents.php
775775
.. _`SwiftMailer's Plugin Documentation`: http://swiftmailer.org/docs/plugins.html

reference/forms/twig_reference.rst

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,25 @@ not be immediately clear, but they're incredibly powerful. Whenever you
120120
render any part of a form, the block that renders it makes use of a number
121121
of variables. By default, these blocks live inside `form_div_layout.html.twig`_.
122122

123-
Look at the ``generic_label`` as an example:
123+
Look at the ``form_label`` as an example:
124124

125125
.. code-block:: jinja
126126
127-
{% block generic_label %}
127+
{% block form_label %}
128+
{% if not compound %}
129+
{% set label_attr = label_attr|merge({'for': id}) %}
130+
{% endif %}
128131
{% if required %}
129-
{% set attr = attr|merge({'class': attr.class|default('') ~ ' required'}) %}
132+
{% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
133+
{% endif %}
134+
{% if label is empty %}
135+
{% set label = name|humanize %}
130136
{% endif %}
131-
<label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>{{ label|trans }}</label>
132-
{% endblock %}
137+
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ label|trans({}, translation_domain) }}</label>
138+
{% endblock form_label %}
133139
134-
This block makes use of 3 variables: ``required``, ``attr`` and ``label``.
140+
This block makes use of several variables: ``compound``, ``label_attr``, ``required``,
141+
``label``, ``name`` and ``translation_domain``.
135142
These variables are made available by the form rendering system. But more
136143
importantly, these are the variables that you can override when calling ``form_label``
137144
(since in this example, you're rendering the label).
@@ -162,4 +169,4 @@ to see what options you have available.
162169
{# does **not** work - the variables are not recursive #}
163170
{{ form_widget(form, { 'attr': {'class': 'foo'} }) }}
164171
165-
.. _`form_div_layout.html.twig`: https://github.com/symfony/symfony/blob/2.0/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
172+
.. _`form_div_layout.html.twig`: https://github.com/symfony/symfony/blob/2.1/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

0 commit comments

Comments
 (0)