Skip to content

Improve choice option documentation for entity form field type #3098

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
23 changes: 18 additions & 5 deletions reference/forms/types/entity.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ as either a ``select`` tag, a set or radio buttons or a series of checkboxes
If the entity object does not have a ``__toString()`` method the ``property`` option
is needed.

Using Choices
~~~~~~~~~~~~~

If you want to limit the entities which are available as choices you can provide
them by calling the getter function of an entity:

$builder->add('users', 'entity', array(
'class' => 'AcmeHelloBundle:User',
'choices' => $group->getUsers(),
));

Using a Custom Query for the Entities
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -132,15 +143,17 @@ Overridden Options
choices
~~~~~~~

**default**: ``null``
**type**: array || ``\Traversable`` **default**: all entities

If the choices are provided only these will be available. The choices need to
be a traversable collection such as the
``Doctrine\Common\Collections\ArrayCollection`` containing only entities of the
specified class.

choice_list
~~~~~~~~~~~

**default**: all entities selected

The choices will default to all entities selected with one of the options that
are documented above.
**default**: ``null``

Inherited options
-----------------
Expand Down