Skip to content

Commit 139fb13

Browse files
committed
Merge branch '6.1' into 6.2
* 6.1: [Form] Document using TranslatableMessage in form Fields
2 parents d66f33f + 67296ed commit 139fb13

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

reference/forms/types/options/choice_label.rst.inc

+6
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,15 @@ more control::
2525

2626
// or if you want to translate some key
2727
//return 'form.choice.'.$key;
28+
//return new TranslatableMessage($key, false === $choice ? [] : ['%status%' => $value], 'store');
2829
},
2930
]);
3031

32+
.. versionadded:: 5.2
33+
34+
The support for ``TranslatableMessage`` objects in ``choice_label`` was
35+
introduced in Symfony 5.2.
36+
3137
This method is called for *each* choice, passing you the ``$choice`` and
3238
``$key`` from the choices array (additional ``$value`` is related to `choice_value`_).
3339
This will give you:

reference/forms/types/options/label.rst.inc

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
``label``
22
~~~~~~~~~
33

4-
**type**: ``string`` **default**: The label is "guessed" from the field name
4+
**type**: ``string`` or ``TranslatableMessage`` **default**: The label is "guessed" from the field name
55

66
Sets the label that will be used when rendering the field. Setting to ``false``
7-
will suppress the label. The label can also be set in the template:
7+
will suppress the label.
8+
9+
use Symfony\Component\Translation\TranslatableMessage;
10+
11+
$builder
12+
->add('zipCode', null, [
13+
'label' => 'The ZIP/Postal code',
14+
// optionally, you can use TranslatableMessage objects as the label content
15+
'label' => new TranslatableMessage('address.zipCode', ['%country%' => $country], 'address'),
16+
])
17+
18+
.. versionadded:: 5.2
19+
20+
The support for ``TranslatableMessage`` objects in ``label`` was
21+
introduced in Symfony 5.2.
22+
23+
The label can also be set in the template:
824

925
.. configuration-block::
1026

0 commit comments

Comments
 (0)