Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Form] Add choice_translation_parameters option#13677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletionsreference/forms/types/choice.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,6 +18,7 @@ To use this field, you must specify *either* ``choices`` or ``choice_loader`` op
| | - `choice_label`_ |
| | - `choice_loader`_ |
| | - `choice_name`_ |
| | - `choice_translation_parameters`_ |
| | - `choice_translation_domain`_ |
| | - `choice_value`_ |
| | - `expanded`_ |
Expand DownExpand Up@@ -225,6 +226,8 @@ correct types will be assigned to the model.

.. include:: /reference/forms/types/options/choice_name.rst.inc

.. include:: /reference/forms/types/options/choice_translation_parameters.rst.inc

.. include:: /reference/forms/types/options/choice_translation_domain.rst.inc

.. include:: /reference/forms/types/options/choice_value.rst.inc
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
choice_translation_parameters
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**type**: ``array``, ``callable``, ``string`` or :class:`Symfony\\Component\\PropertyAccess\\PropertyPath` **default**: ``[]``

The choice values are translated before displaying it, so it can contain
:ref:`translation placeholders <component-translation-placeholders>`.
This option defines the values used to replace those placeholders. This can be
an associative array where the keys match the choice keys and the values
are the attributes for each choice, a callable or a property path
(just like `choice_label`_).

Given this translation message:

.. code-block:: yaml

# translations/messages.en.yaml
form.order.yes: 'I confirm my order to the company %company%'
form.order.no: 'I cancel my order'

You can specify the placeholder values as follows::

$builder->add('id', null, [
'choice' => [
'form.order.yes' => true,
'form.order.no' => false,
],
'choice_translation_parameters' => function ($choice, $key, $value) {
if (false === $choice) {
return [];
}

return ['%company%' => 'ACME Inc.']
},
]);

If an array, the keys of the ``choices`` array must be used as keys::

$builder->add('id', null, [
'choice' => [
'form.order.yes' => true,
'form.order.no' => false,
],
'choice_translation_parameters' => [
'form.order.yes' => ['%company%' => 'ACME Inc.'],
'form.order.no' => [],
],
]);

The ``choice_translation_parameters`` option of children fields is merged with
the same option of their parents, so children can reuse and/or override any of
the parent placeholders.

[8]ページ先頭

©2009-2025 Movatter.jp