File tree Expand file tree Collapse file tree 1 file changed +25
-4
lines changed Expand file tree Collapse file tree 1 file changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -275,12 +275,33 @@ These options inherit from the :doc:`ChoiceType </reference/forms/types/choice>`
275275
276276.. include :: /reference/forms/types/options/placeholder.rst.inc
277277
278- .. include :: /reference/forms/types/options/preferred_choices.rst.inc
278+ preferred_choices
279+ ~~~~~~~~~~~~~~~~~
279280
280- .. note ::
281+ **type **: ``array `` or ``callable `` **default **: ``array() ``
282+
283+ This option allows you to move certain choices to the top of your list with a visual
284+ separator between them and the rest of the options. This option expects an array
285+ of entity objects::
286+
287+ use AppBundle\Entity\User;
288+ use Symfony\Bridge\Doctrine\Form\Type\EntityType;
289+ // ...
290+
291+ $builder->add('users', EntityType::class, array(
292+ 'class' => User::class,
293+ // this method must return an array of User entities
294+ 'preferred_choices' => $group->getPreferredUsers(),
295+ ));
296+
297+ The preferred choices are only meaningful when rendering a ``select `` element
298+ (i.e. ``expanded `` false). The preferred choices and normal choices are separated
299+ visually by a set of dotted lines (i.e. ``------------------- ``). This can be customized
300+ when rendering the field:
301+
302+ .. code-block :: twig
281303
282- This option expects an array of entity objects (that's actually the same as with
283- the ``ChoiceType `` field, which requires an array of the preferred "values").
304+ {{ form_widget(form.publishAt, { 'separator': '=====' }) }}
284305
285306 .. include :: /reference/forms/types/options/choice_type_translation_domain.rst.inc
286307
You can’t perform that action at this time.
0 commit comments