Skip to content

Commit a0b617a

Browse files
eikesweaverryan
authored andcommitted
Improve choice option documentation for entity form field type
1 parent edc0345 commit a0b617a

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

reference/forms/types/entity.rst

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ as either a ``select`` tag, a set or radio buttons or a series of checkboxes
5555
If the entity object does not have a ``__toString()`` method the ``property`` option
5656
is needed.
5757

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+
5869
Using a Custom Query for the Entities
5970
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6071

@@ -132,15 +143,17 @@ Overridden Options
132143
choices
133144
~~~~~~~
134145

135-
**default**: ``null``
146+
**type**: array || ``\Traversable`` **default**: all entities
147+
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.
136152

137153
choice_list
138154
~~~~~~~~~~~
139155

140-
**default**: all entities selected
141-
142-
The choices will default to all entities selected with one of the options that
143-
are documented above.
156+
**default**: ``null``
144157

145158
Inherited options
146159
-----------------

0 commit comments

Comments
 (0)