Skip to content

Commit b72dd7c

Browse files
committed
[Form] Document using TranslatableMessage in form Fields
1 parent 0718196 commit b72dd7c

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ 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

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

Lines changed: 18 additions & 2 deletions
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+
])
15+
16+
// ...
17+
18+
->add('zipCode', null, [
19+
'label' => new TranslatableMessage('address.zipCode', ['%country%' => $country], 'address'),
20+
])
21+
;
22+
23+
The label can also be set in the template:
824

925
.. configuration-block::
1026

0 commit comments

Comments
 (0)