Skip to content

Fixed the preferred_choices option for Enttiy type #10072

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

Merged
merged 1 commit into from
Jul 16, 2018
Merged
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
29 changes: 25 additions & 4 deletions reference/forms/types/entity.rst
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,33 @@ These options inherit from the :doc:`ChoiceType </reference/forms/types/choice>`

.. include:: /reference/forms/types/options/placeholder.rst.inc

.. include:: /reference/forms/types/options/preferred_choices.rst.inc
preferred_choices
~~~~~~~~~~~~~~~~~

.. note::
**type**: ``array`` or ``callable`` **default**: ``array()``

This option allows you to move certain choices to the top of your list with a visual
separator between them and the rest of the options. This option expects an array
of entity objects::

use AppBundle\Entity\User;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
// ...

$builder->add('users', EntityType::class, array(
'class' => User::class,
// this method must return an array of User entities
'preferred_choices' => $group->getPreferredUsers(),
));

The preferred choices are only meaningful when rendering a ``select`` element
(i.e. ``expanded`` false). The preferred choices and normal choices are separated
visually by a set of dotted lines (i.e. ``-------------------``). This can be customized
when rendering the field:

.. code-block:: twig

This option expects an array of entity objects (that's actually the same as with
the ``ChoiceType`` field, which requires an array of the preferred "values").
{{ form_widget(form.publishAt, { 'separator': '=====' }) }}

.. include:: /reference/forms/types/options/choice_type_translation_domain.rst.inc

Expand Down