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

Appearance settings

Commit bf13394

Browse filesBrowse files
committed
[Form] fixed EntityType choice options
1 parent 88f0238 commit bf13394
Copy full SHA for bf13394

File tree

Expand file treeCollapse file tree

1 file changed

+31
-9
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+31
-9
lines changed

‎reference/forms/types/entity.rst

Copy file name to clipboardExpand all lines: reference/forms/types/entity.rst
+31-9Lines changed: 31 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`_ |
@@ -115,7 +115,7 @@ choice_label
115115
The ``choice_label`` option was introduced in Symfony 2.7. Prior to Symfony
116116
2.7, it was called ``property`` (which has the same functionality).
117117

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

120120
This is the property that should be used for displaying the entities as text in
121121
the HTML element::
@@ -183,6 +183,32 @@ the entity and return an instance of ``QueryBuilder``.
183183
Overridden Options
184184
------------------
185185

186+
choice_name
187+
~~~~~~~~~~~
188+
189+
.. versionadded:: 2.7
190+
The ``choice_name`` option was introduced in Symfony 2.7.
191+
192+
**type**: ``string``, ``callable`` or :class:`Symfony\\Component\\PropertyAccess\\PropertyPath` **default**: id
193+
194+
By default the name of each field is the id of the entity, if it can be get in
195+
the class metadata by an internal id reader.
196+
197+
choice_value
198+
~~~~~~~~~~~~
199+
200+
.. versionadded:: 2.7
201+
The ``choice_value`` option was introduced in Symfony 2.7.
202+
203+
**type**: ``string``, ``callable`` or :class:`Symfony\\Component\\PropertyAccess\\PropertyPath` **default**: id
204+
205+
As for the ``choice_name`` option, ``choice_value`` use the id by default.
206+
It allows an optimization in the :class:``Symfony\\Bridge\\Doctrine\\Form\\ChoiceList\\Loader\\DoctrineChoiceLoader`` which will
207+
only load the ids passed as values while the form submission, preventing all entities,
208+
even with a custom ``query_builder`` to be loaded.
209+
If it can be usefull for API to use an entity property as string value, you
210+
will gain performances by letting this option set by default.
211+
186212
choices
187213
~~~~~~~
188214

@@ -208,12 +234,8 @@ type:
208234

209235
.. include:: /reference/forms/types/options/choice_attr.rst.inc
210236

211-
.. include:: /reference/forms/types/options/choice_name.rst.inc
212-
213237
.. include:: /reference/forms/types/options/choice_translation_domain.rst.inc
214238

215-
.. include:: /reference/forms/types/options/choice_value.rst.inc
216-
217239
.. include:: /reference/forms/types/options/expanded.rst.inc
218240

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.