Skip to content

Commit a655106

Browse files
author
Vladyslav Riabchenko
committed
confirm with 28635
1 parent 32e79e1 commit a655106

15 files changed

+493
-334
lines changed

reference/forms/types/button.rst

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ A simple, non-responsive button.
1313
| options | - `disabled`_ |
1414
| | - `label`_ |
1515
| | - `translation_domain`_ |
16-
| | - `translation_parameters`_ |
16+
| | - `label_translation_parameters`_ |
17+
| | - `attr_translation_parameters`_ |
1718
+----------------------+----------------------------------------------------------------------+
1819
| Parent type | none |
1920
+----------------------+----------------------------------------------------------------------+
@@ -53,4 +54,82 @@ as a key. This can be useful when you need to set a custom class for the button:
5354

5455
.. include:: /reference/forms/types/options/button_translation_domain.rst.inc
5556

56-
.. include:: /reference/forms/types/options/button_translation_parameters.rst.inc
57+
label_translation_parameters
58+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59+
60+
**type**: ``array`` **default**: ``array()``
61+
62+
Translated `label`_ can contain
63+
:ref:`placeholders <component-translation-placeholders>`.
64+
This option allows you to pass an array of parameters in order to replace
65+
placeholders with actual values.
66+
67+
Given this translation message:
68+
69+
.. code-block:: yaml
70+
71+
# translations/messages.en.yml
72+
form.order.submit_to_company: Send an order to %company%
73+
74+
you can specify placeholder value:
75+
76+
.. code-block:: php
77+
78+
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
79+
// ...
80+
81+
$builder->add('send', ButtonType::class, array(
82+
'label' => 'form.order.submit_to_company',
83+
'label_translation_parameters' => array(
84+
'%company%' => 'ACME Inc.',
85+
),
86+
));
87+
88+
Note that `label_translation_parameters` of buttons are merged with those of its
89+
parent. In other words the parent's translation parameters are available for
90+
children's buttons but can be overriden:
91+
92+
.. code-block:: php
93+
94+
// App/Controller/OrderController.php
95+
use App\Form\OrderType;
96+
// ...
97+
98+
$form = $this->createForm(OrderType::class, $order, array(
99+
// available to all children, grandchildren and so on.
100+
'label_translation_parameters' => array(
101+
'%company%' => 'ACME',
102+
),
103+
));
104+
105+
.. code-block:: php
106+
107+
// App/Form/OrderType.php
108+
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
109+
// ...
110+
111+
$builder->add('send', ButtonType::class, array(
112+
'label' => 'form.order.submit_to_company',
113+
// Value of parent's 'label_translation_parameters' will be merged with
114+
// this field's empty 'label_translation_parameters'.
115+
// array('%company%' => 'ACME') will be used to translate this label.
116+
));
117+
118+
.. code-block:: php
119+
120+
// App/Form/OrderType.php
121+
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
122+
// ...
123+
124+
$builder->add('send', ButtonType::class, array(
125+
'label' => 'form.order.submit_to_company',
126+
'label_translation_parameters' => array(
127+
'%company%' => 'American Company Making Everything',
128+
),
129+
// Value of parent's 'label_translation_parameters' will be merged with
130+
// this button's 'label_translation_parameters'.
131+
// array('%company%' => 'American Company Making Everything')
132+
// will be used to translate this label.
133+
));
134+
135+
.. include:: /reference/forms/types/options/attr_translation_parameters.rst.inc

reference/forms/types/choice.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ To use this field, you must specify *either* ``choices`` or ``choice_loader`` op
4545
| | - `mapped`_ |
4646
| | - `required`_ |
4747
| | - `translation_domain`_ |
48-
| | - `translation_parameters`_ |
48+
| | - `label_translation_parameters`_ |
49+
| | - `attr_translation_parameters`_ |
50+
| | - `helptranslation_parameters`_ |
4951
+-------------+------------------------------------------------------------------------------+
5052
| Parent type | :doc:`FormType </reference/forms/types/form>` |
5153
+-------------+------------------------------------------------------------------------------+
@@ -298,7 +300,11 @@ These options inherit from the :doc:`FormType </reference/forms/types/form>`:
298300

299301
.. include:: /reference/forms/types/options/choice_type_translation_domain.rst.inc
300302

301-
.. include:: /reference/forms/types/options/choice_type_translation_parameters.rst.inc
303+
.. include:: /reference/forms/types/options/label_translation_parameters.rst.inc
304+
305+
.. include:: /reference/forms/types/options/attr_translation_parameters.rst.inc
306+
307+
.. include:: /reference/forms/types/options/help_translation_parameters.rst.inc
302308

303309
Field Variables
304310
---------------

reference/forms/types/entity.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ objects from the database.
3232
| | - `placeholder`_ |
3333
| | - `preferred_choices`_ |
3434
| | - `translation_domain`_ |
35-
| | - `translation_parameters`_ |
35+
| | - `label_translation_parameters`_ |
36+
| | - `attr_translation_parameters`_ |
37+
| | - `help_translation_parameters`_ |
3638
| | - `trim`_ |
3739
| | |
3840
| | from the :doc:`FormType </reference/forms/types/form>`: |
@@ -308,7 +310,11 @@ when rendering the field:
308310
309311
.. include:: /reference/forms/types/options/choice_type_translation_domain.rst.inc
310312

311-
.. include:: /reference/forms/types/options/entity_type_translation_parameters.rst.inc
313+
.. include:: /reference/forms/types/options/label_translation_parameters.rst.inc
314+
315+
.. include:: /reference/forms/types/options/attr_translation_parameters.rst.inc
316+
317+
.. include:: /reference/forms/types/options/help_translation_parameters.rst.inc
312318

313319
.. include:: /reference/forms/types/options/choice_type_trim.rst.inc
314320

reference/forms/types/form.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ on all types for which ``FormType`` is the parent.
2222
| | - `help`_ |
2323
| | - `help_attr`_ |
2424
| | - `help_html`_ |
25+
| | - `help_translation_parameters`_ |
2526
| | - `inherit_data`_ |
2627
| | - `invalid_message`_ |
2728
| | - `invalid_message_parameters`_ |
@@ -42,6 +43,8 @@ on all types for which ``FormType`` is the parent.
4243
| | - `disabled`_ |
4344
| | - `label`_ |
4445
| | - `translation_domain`_ |
46+
| | - `label_translation_parameters`_ |
47+
| | - `attr_translation_parameters`_ |
4548
| | - `translation_parameters`_ |
4649
+-----------+--------------------------------------------------------------------+
4750
| Parent | none |
@@ -114,6 +117,8 @@ The actual default value of this option depends on other field options:
114117

115118
.. include:: /reference/forms/types/options/help_html.rst.inc
116119

120+
.. include:: /reference/forms/types/options/help_translation_parameters.rst.inc
121+
117122
.. include:: /reference/forms/types/options/inherit_data.rst.inc
118123

119124
.. include:: /reference/forms/types/options/invalid_message.rst.inc
@@ -169,4 +174,6 @@ of the form type tree (i.e. it cannot be used as a form type on its own).
169174

170175
.. include:: /reference/forms/types/options/translation_domain.rst.inc
171176

172-
.. include:: /reference/forms/types/options/translation_parameters.rst.inc
177+
.. include:: /reference/forms/types/options/label_translation_parameters.rst.inc
178+
179+
.. include:: /reference/forms/types/options/attr_translation_parameters.rst.inc
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
attr_translation_parameters
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
**type**: ``array`` **default**: ``array()``
5+
6+
Some translated `attr`_ (``title`` and ``placeholder``) can
7+
contain :ref:`placeholders <component-translation-placeholders>`.
8+
This option allows you to pass an array of parameters in order to replace
9+
placeholders with actual values.
10+
11+
Given this translation message:
12+
13+
.. code-block:: yaml
14+
15+
# translations/messages.en.yml
16+
form.order.id.placeholder: Enter unique identifier of the order to %company%
17+
form.order.id.title: This will be the reference in communications with %company%
18+
19+
you can specify placeholder value:
20+
21+
.. code-block:: php
22+
23+
$builder->add('id', null, array(
24+
'attr' => array(
25+
'placeholder' => 'form.order.id.placeholder',
26+
'title' => 'form.order.id.title',
27+
),
28+
'attr_translation_parameters' => [
29+
'%company%' => 'ACME Inc.'
30+
]
31+
));
32+
33+
Note that `attr_translation_parameters` of children fields are merged with those
34+
of its parent. In other words the parent's translation parameters are available
35+
for children but can be overriden:
36+
37+
.. code-block:: php
38+
39+
// App/Controller/OrderController.php
40+
use App\Form\OrderType;
41+
// ...
42+
43+
$form = $this->createForm(OrderType::class, $order, array(
44+
// available to all children, grandchildren and so on.
45+
'attr_translation_parameters' => array(
46+
'%company%' => 'ACME',
47+
),
48+
));
49+
50+
.. code-block:: php
51+
52+
// App/Form/OrderType.php
53+
// ...
54+
55+
$builder->add('id', null, array(
56+
'attr' => array(
57+
'placeholder' => 'form.order.id.placeholder',
58+
'title' => 'form.order.id.title',
59+
),
60+
// Value of parent's 'attr_translation_parameters' will be merged with
61+
// this field's empty 'attr_translation_parameters'.
62+
// array('%company%' => 'ACME') will be used to translate 'placeholder' and 'title'.
63+
));
64+
65+
.. code-block:: php
66+
67+
// App/Form/OrderType.php
68+
// ...
69+
70+
$builder->add('id', null, array(
71+
'attr' => array(
72+
'placeholder' => 'form.order.id.placeholder',
73+
'title' => 'form.order.id.title',
74+
),
75+
'attr_translation_parameters' => array(
76+
'%company%' => 'American Company Making Everything',
77+
),
78+
// Value of parent's 'attr_translation_parameters' will be merged with
79+
// this field's 'attr_translation_parameters'.
80+
// array('%company%' => 'American Company Making Everything')
81+
// will be used to translate 'placeholder' and 'title'.
82+
));

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

Lines changed: 0 additions & 54 deletions
This file was deleted.

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

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)