Skip to content

Commit 4d51f28

Browse files
committed
minor #16717 [Form] Document using TranslatableMessage for label and choice_label (Sébastien Lévêque)
This PR was merged into the 5.4 branch. Discussion ---------- [Form] Document using TranslatableMessage for label and choice_label Document using TranslatableMessage for label and choice_label like form help ([15527](#15527)) Commits ------- b72dd7c [Form] Document using TranslatableMessage in form Fields
2 parents 17afcec + b72dd7c commit 4d51f28

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)