@@ -62,25 +62,29 @@ be listed inside the choice field::
6262 // ...
6363
6464 $builder->add('users', EntityType::class, array(
65+ // query choices from this entity
6566 'class' => 'AppBundle:User',
67+
68+ // use the User.username property as the visible option string
6669 'choice_label' => 'username',
70+
71+ // used to render a select box, check boxes or radios
72+ // 'multiple' => true,
73+ // 'expanded' => true,
6774 ));
6875
69- In this case, all ``User `` objects will be loaded from the database and
70- rendered as either a ``select `` tag, a set or radio buttons or a series
71- of checkboxes (this depends on the ``multiple `` and ``expanded `` values).
72- Because of the `choice_label `_ option, the ``username `` property (usually by calling
73- ``getUsername() ``) will be used as the text to display in the field.
76+ This will build a ``select `` drop-down containing *all * of the ``User `` objects
77+ in the database. To render radio buttons or checkboxes instead, change the
78+ `multiple `_ and `expanded `_ options.
7479
75- If you omit the ``choice_label `` option, then your entity *must * have a ``__toString() ``
76- method.
80+ .. _ref-form-entity-query-builder :
7781
7882Using a Custom Query for the Entities
7983~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8084
81- If youneed tospecify a custom query to use when fetching the entities
85+ If youwant tocreate a custom query to use when fetching the entities
8286(e.g. you only want to return some entities, or need to order them), use
83- the `` query_builder `` option. The easiest way to use the option is as follows ::
87+ the `query_builder `_ option::
8488
8589 use Doctrine\ORM\EntityRepository;
8690 use Symfony\Bridge\Doctrine\Form\Type\EntityType;
@@ -92,15 +96,17 @@ the ``query_builder`` option. The easiest way to use the option is as follows::
9296 return $er->createQueryBuilder('u')
9397 ->orderBy('u.username', 'ASC');
9498 },
99+ 'choice_label' => 'username',
95100 ));
96101
97102.. _reference-forms-entity-choices :
98103
99104Using Choices
100105~~~~~~~~~~~~~
101106
102- If you already have the exact collection of entities that you want included
103- in the choice element, you can simply pass them via the ``choices `` key.
107+ If you already have the exact collection of entities that you want to include
108+ in the choice element, just pass them via the ``choices `` key.
109+
104110For example, if you have a ``$group `` variable (passed into your form perhaps
105111as a form option) and ``getUsers `` returns a collection of ``User `` entities,
106112then you can supply the ``choices `` option directly::
@@ -193,11 +199,12 @@ query_builder
193199
194200**type **: ``Doctrine\ORM\QueryBuilder `` or a Closure
195201
196- If specified, this is used to query the subset of options (and their
197- order) that should be used for the field. The value of this option can
198- either be a ``QueryBuilder `` object or a Closure. If using a Closure,
199- it should take a single argument, which is the ``EntityRepository `` of
200- the entity and return an instance of ``QueryBuilder ``.
202+ Allows you to create a custom query for your choices. See
203+ :ref: `ref-form-entity-query-builder ` for an example.
204+
205+ The value of this option can either be a ``QueryBuilder `` object or a Closure.
206+ When using a Closure, you will be passed the ``EntityRepository `` of the entity
207+ as the only argument and should return a ``QueryBuilder ``.
201208
202209Overridden Options
203210------------------