@@ -18,8 +18,8 @@ objects from the database.
18
18
| | - `query_builder `_ |
19
19
| | - `em `_ |
20
20
+-------------+------------------------------------------------------------------+
21
- | Overridden | - `choices ` |
22
- | Options | - `choice_list ` |
21
+ | Overridden | - `choices `_ |
22
+ | Options | - `choice_list `_ |
23
23
+-------------+------------------------------------------------------------------+
24
24
| Inherited | - `required `_ |
25
25
| options | - `label `_ |
@@ -55,17 +55,6 @@ as either a ``select`` tag, a set or radio buttons or a series of checkboxes
55
55
If the entity object does not have a ``__toString() `` method the ``property `` option
56
56
is needed.
57
57
58
- Using Choices
59
- ~~~~~~~~~~~~~
60
-
61
- If you want to limit the entities which are available as choices you can provide
62
- them by calling the getter function of an entity:
63
-
64
- $builder->add('users', 'entity', array(
65
- 'class' => 'AcmeHelloBundle:User',
66
- 'choices' => $group->getUsers(),
67
- ));
68
-
69
58
Using a Custom Query for the Entities
70
59
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
71
60
@@ -84,6 +73,22 @@ option. The easiest way to use the option is as follows::
84
73
},
85
74
));
86
75
76
+ .. _reference-forms-entity-choices :
77
+
78
+ Using Choices
79
+ ~~~~~~~~~~~~~
80
+
81
+ If you already have the exact collection of entities that you want included
82
+ in the choice element, you can simply pass them via the ``choices `` key.
83
+ For example, if you have a ``$group `` variable (passed into your form perhaps
84
+ as a form option) and ``getUsers `` returns a collection of ``User `` entities,
85
+ then you can supply the ``choices `` option directly::
86
+
87
+ $builder->add('users', 'entity', array(
88
+ 'class' => 'AcmeHelloBundle:User',
89
+ 'choices' => $group->getUsers(),
90
+ ));
91
+
87
92
.. include :: /reference/forms/types/options/select_how_rendered.rst.inc
88
93
89
94
Field Options
@@ -143,17 +148,21 @@ Overridden Options
143
148
choices
144
149
~~~~~~~
145
150
146
- **type **: array || ``\Traversable `` **default **: all entities
151
+ **type **: array || ``\Traversable `` **default **: `` null ``
147
152
148
- If the choices are provided only these will be available. The choices need to
149
- be a traversable collection such as the
150
- ``Doctrine\Common\Collections\ArrayCollection `` containing only entities of the
151
- specified class.
153
+ Instead of allowing the `class `_ and `query_builder `_ options to fetch the
154
+ entities to include for you, you can pass the ``choices `` option directly.
155
+ See :ref: `reference-forms-entity-choices `.
152
156
153
157
choice_list
154
158
~~~~~~~~~~~
155
159
156
- **default **: ``null ``
160
+ **default **: :class: `Symfony\\ Bridge\\ Doctrine\\ Form\\ ChoiceList\\ EntityChoiceList `
161
+
162
+ The purpose of the ``entity `` type is to create and configure this ``EntityChoiceList ``
163
+ for you, by using all of the above options. If you need to override this
164
+ option, you may just consider using the :doc: `/reference/forms/types/choice `
165
+ directly.
157
166
158
167
Inherited options
159
168
-----------------
0 commit comments