Skip to content

Commit ede5eae

Browse files
committed
Merge branch '5.4' into 6.2
* 5.4: Don't use double backquotes in the comments [Form] Add some basic docs for Twig Form field helpers
2 parents ff65866 + d4e8e64 commit ede5eae

File tree

6 files changed

+64
-15
lines changed

6 files changed

+64
-15
lines changed

components/cache/adapters/array_cache_adapter.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ method::
1515
// until the current PHP process finishes)
1616
$defaultLifetime = 0,
1717

18-
// if ``true``, the values saved in the cache are serialized before storing them
18+
// if true, the values saved in the cache are serialized before storing them
1919
$storeSerialized = true,
2020

2121
// the maximum lifetime (in seconds) of the entire cache (after this time, the

event_dispatcher.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ could listen to the ``mailer.post_send`` event and change the method's return va
779779
public function onMailerPostSend(AfterSendMailEvent $event)
780780
{
781781
$returnValue = $event->getReturnValue();
782-
// modify the original ``$returnValue`` value
782+
// modify the original $returnValue value
783783

784784
$event->setReturnValue($returnValue);
785785
}

form/form_customization.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,50 @@ control over how each form field is rendered, so you can fully customize them:
8787
Later in this article you can find the full reference of these Twig
8888
functions with more usage examples.
8989

90+
.. _reference-forms-twig-field-helpers:
91+
92+
Form Field Helpers
93+
------------------
94+
95+
The ``form_*()`` helpers shown in the previous section render different parts of
96+
the form field, including all its HTML elements. Some developers and designers
97+
struggle with this behavior, because it hides all the HTML elements in form
98+
themes which are not trivial to customize.
99+
100+
That's why Symfony provides other Twig form helpers that render the value of
101+
each form field part without adding any HTML around it:
102+
103+
* ``field_name()``
104+
* ``field_value()``
105+
* ``field_label()``
106+
* ``field_help()``
107+
* ``field_errors()``
108+
* ``field_choices()`` (an iterator for choice fields; e.g. for ``<select>``)
109+
110+
When using these helpers, you must write all the HTML contents for all form
111+
fields, so you no longer have to deal with form themes:
112+
113+
.. code-block:: html+twig
114+
115+
<input
116+
name="{{ field_name(form.username) }}"
117+
value="{{ field_value(form.username) }}"
118+
placeholder="{{ field_label(form.username) }}"
119+
class="form-control"
120+
/>
121+
122+
<select name="{{ field_name(form.country) }}" class="form-control">
123+
<option value="">{{ field_label(form.country) }}</option>
124+
125+
{% for label, value in field_choices(form.country) %}
126+
<option value="{{ value }}">{{ label }}</option>
127+
{% endfor %}
128+
</select>
129+
130+
.. versionadded:: 5.2
131+
132+
The ``field_*()`` helpers were introduced in Symfony 5.2.
133+
90134
Form Rendering Variables
91135
------------------------
92136

reference/twig_reference.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,12 @@ explained in the article about :doc:`customizing form rendering </form/form_cust
349349
* :ref:`form_help() <reference-forms-twig-help>`
350350
* :ref:`form_row() <reference-forms-twig-row>`
351351
* :ref:`form_rest() <reference-forms-twig-rest>`
352+
* :ref:`field_name() <reference-forms-twig-field-helpers>`
353+
* :ref:`field_value() <reference-forms-twig-field-helpers>`
354+
* :ref:`field_label() <reference-forms-twig-field-helpers>`
355+
* :ref:`field_help() <reference-forms-twig-field-helpers>`
356+
* :ref:`field_errors() <reference-forms-twig-field-helpers>`
357+
* :ref:`field_choices() <reference-forms-twig-field-helpers>`
352358

353359
.. _reference-twig-filters:
354360

service_container/autowiring.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ adding a service alias:
212212
# ...
213213
214214
# but this fixes it!
215-
# the ``app.rot13.transformer`` service will be injected when
216-
# an ``App\Util\Rot13Transformer`` type-hint is detected
215+
# the "app.rot13.transformer" service will be injected when
216+
# an App\Util\Rot13Transformer type-hint is detected
217217
App\Util\Rot13Transformer: '@app.rot13.transformer'
218218
219219
.. code-block:: xml
@@ -247,8 +247,8 @@ adding a service alias:
247247
->autowire();
248248
249249
// but this fixes it!
250-
// the ``app.rot13.transformer`` service will be injected when
251-
// an ``App\Util\Rot13Transformer`` type-hint is detected
250+
// the "app.rot13.transformer" service will be injected when
251+
// an App\Util\Rot13Transformer type-hint is detected
252252
$services->alias(Rot13Transformer::class, 'app.rot13.transformer');
253253
};
254254
@@ -352,8 +352,8 @@ To fix that, add an :ref:`alias <service-autowiring-alias>`:
352352
353353
$services->set(Rot13Transformer::class);
354354
355-
// the ``App\Util\Rot13Transformer`` service will be injected when
356-
// an ``App\Util\TransformerInterface`` type-hint is detected
355+
// the App\Util\Rot13Transformer service will be injected when
356+
// an App\Util\TransformerInterface type-hint is detected
357357
$services->alias(TransformerInterface::class, Rot13Transformer::class);
358358
};
359359
@@ -518,13 +518,13 @@ the injection::
518518
$services->set(Rot13Transformer::class)->autowire();
519519
$services->set(UppercaseTransformer::class)->autowire();
520520
521-
// the ``App\Util\UppercaseTransformer`` service will be
522-
// injected when an ``App\Util\TransformerInterface``
523-
// type-hint for a ``$shoutyTransformer`` argument is detected.
521+
// the App\Util\UppercaseTransformer service will be
522+
// injected when an App\Util\TransformerInterface
523+
// type-hint for a $shoutyTransformer argument is detected.
524524
$services->alias(TransformerInterface::class.' $shoutyTransformer', UppercaseTransformer::class);
525525
526526
// If the argument used for injection does not match, but the
527-
// type-hint still matches, the ``App\Util\Rot13Transformer``
527+
// type-hint still matches, the App\Util\Rot13Transformer
528528
// service will be injected.
529529
$services->alias(TransformerInterface::class, Rot13Transformer::class);
530530

testing.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,11 +566,10 @@ In the above example, the test validates that the HTTP response was successful
566566
and the request body contains a ``<h1>`` tag with ``"Hello world"``.
567567

568568
The ``request()`` method also returns a crawler, which you can use to
569-
create more complex assertions in your tests::
569+
create more complex assertions in your tests (e.g. to count the number of page
570+
elements that match a given CSS selector)::
570571

571572
$crawler = $client->request('GET', '/post/hello-world');
572-
573-
// for instance, count the number of ``.comment`` elements on the page
574573
$this->assertCount(4, $crawler->filter('.comment'));
575574

576575
You can learn more about the crawler in :doc:`/testing/dom_crawler`.

0 commit comments

Comments
 (0)