Skip to content

Commit 439283a

Browse files
committed
minor #6444 [Form] fixed EntityType choice options (HeahDude)
This PR was merged into the 2.7 branch. Discussion ---------- [Form] fixed EntityType choice options | Q | A | |-----------|-------| | branch | 2.7+ | | doc fix | yes We should point these overridden options from the `ChoiceType`, so users keep the benefit of the optimization made in the `DoctrineChoiceLoader`. Commits ------- 302afe5 [Form] fixed EntityType choice options
2 parents e706ecf + 302afe5 commit 439283a

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

reference/forms/types/entity.rst

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ objects from the database.
1717
| | - `em`_ |
1818
| | - `query_builder`_ |
1919
+-------------+------------------------------------------------------------------+
20-
| Overridden | - `choices`_ |
21-
| options | - `data_class`_ |
20+
| Overridden | - `choice_name`_ |
21+
| options | - `choice_value`_ |
22+
| | - `choices`_ |
23+
| | - `data_class`_ |
2224
+-------------+------------------------------------------------------------------+
2325
| Inherited | from the :doc:`choice </reference/forms/types/choice>` type: |
2426
| options | |
2527
| | - `choice_attr`_ |
26-
| | - `choice_name`_ |
2728
| | - `choice_translation_domain`_ |
28-
| | - `choice_value`_ |
2929
| | - `expanded`_ |
3030
| | - `group_by`_ |
3131
| | - `multiple`_ |
@@ -124,7 +124,7 @@ choice_label
124124
The ``choice_label`` option was introduced in Symfony 2.7. Prior to Symfony
125125
2.7, it was called ``property`` (which has the same functionality).
126126

127-
**type**: ``string`` or ``callable``
127+
**type**: ``string``, ``callable`` or :class:`Symfony\\Component\\PropertyAccess\\PropertyPath`
128128

129129
This is the property that should be used for displaying the entities as text in
130130
the HTML element::
@@ -194,6 +194,40 @@ return a ``QueryBuilder``.
194194
Overridden Options
195195
------------------
196196

197+
choice_name
198+
~~~~~~~~~~~
199+
200+
.. versionadded:: 2.7
201+
The ``choice_name`` option was introduced in Symfony 2.7.
202+
203+
**type**: ``string``, ``callable`` or :class:`Symfony\\Component\\PropertyAccess\\PropertyPath` **default**: id
204+
205+
By default the name of each field is the id of the entity, if it can be read
206+
from the class metadata by an internal id reader. Otherwise the process will
207+
fall back to using increasing integers.
208+
209+
choice_value
210+
~~~~~~~~~~~~
211+
212+
.. versionadded:: 2.7
213+
The ``choice_value`` option was introduced in Symfony 2.7.
214+
215+
**type**: ``string``, ``callable`` or :class:`Symfony\\Component\\PropertyAccess\\PropertyPath` **default**: id
216+
217+
As for the ``choice_name`` option, ``choice_value`` uses the id by default.
218+
It allows an optimization in the :class:``Symfony\\Bridge\\Doctrine\\Form\\ChoiceList\\Loader\\DoctrineChoiceLoader`` which will
219+
only load the ids passed as values while the form submission.
220+
It prevents all non submitted entities to be loaded from the database, even
221+
when defining the ``query_builder`` option.
222+
If it may be useful to set this option using an entity's property as string
223+
value (e.g for some API), you will gain performances by letting this option set
224+
by default.
225+
226+
.. note::
227+
228+
If the id cannot be read, for BC, the component checks if the class implements
229+
``__toString()`` and will use an incremental integer otherwise.
230+
197231
choices
198232
~~~~~~~
199233

@@ -219,12 +253,8 @@ type:
219253

220254
.. include:: /reference/forms/types/options/choice_attr.rst.inc
221255

222-
.. include:: /reference/forms/types/options/choice_name.rst.inc
223-
224256
.. include:: /reference/forms/types/options/choice_translation_domain.rst.inc
225257

226-
.. include:: /reference/forms/types/options/choice_value.rst.inc
227-
228258
.. include:: /reference/forms/types/options/expanded.rst.inc
229259

230260
.. include:: /reference/forms/types/options/group_by.rst.inc

0 commit comments

Comments
 (0)