From 2ec5104fc2935bb6685447e97af598e80b528b12 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Thu, 5 Oct 2023 11:55:29 +0200 Subject: [PATCH] [Form] Add `duplicate_preferred_choices` option to `ChoiceType` --- reference/forms/types/choice.rst | 2 ++ reference/forms/types/country.rst | 2 ++ reference/forms/types/currency.rst | 2 ++ reference/forms/types/enum.rst | 2 ++ reference/forms/types/language.rst | 2 ++ reference/forms/types/locale.rst | 2 ++ .../duplicate_preferred_choices.rst.inc | 27 +++++++++++++++++++ reference/forms/types/timezone.rst | 2 ++ 8 files changed, 41 insertions(+) create mode 100644 reference/forms/types/options/duplicate_preferred_choices.rst.inc diff --git a/reference/forms/types/choice.rst b/reference/forms/types/choice.rst index 8266ea1c317..09952efefc3 100644 --- a/reference/forms/types/choice.rst +++ b/reference/forms/types/choice.rst @@ -188,6 +188,8 @@ correct types will be assigned to the model. .. include:: /reference/forms/types/options/choice_value.rst.inc +.. include:: /reference/forms/types/options/duplicate_preferred_choices.rst.inc + .. include:: /reference/forms/types/options/expanded.rst.inc .. include:: /reference/forms/types/options/group_by.rst.inc diff --git a/reference/forms/types/country.rst b/reference/forms/types/country.rst index bf24f6e0089..4d249d9524c 100644 --- a/reference/forms/types/country.rst +++ b/reference/forms/types/country.rst @@ -68,6 +68,8 @@ Inherited Options These options inherit from the :doc:`ChoiceType `: +.. include:: /reference/forms/types/options/duplicate_preferred_choices.rst.inc + .. include:: /reference/forms/types/options/error_bubbling.rst.inc .. include:: /reference/forms/types/options/error_mapping.rst.inc diff --git a/reference/forms/types/currency.rst b/reference/forms/types/currency.rst index 9cffad3d9cf..a90820442a8 100644 --- a/reference/forms/types/currency.rst +++ b/reference/forms/types/currency.rst @@ -51,6 +51,8 @@ Inherited Options These options inherit from the :doc:`ChoiceType `: +.. include:: /reference/forms/types/options/duplicate_preferred_choices.rst.inc + .. include:: /reference/forms/types/options/error_bubbling.rst.inc .. include:: /reference/forms/types/options/expanded.rst.inc diff --git a/reference/forms/types/enum.rst b/reference/forms/types/enum.rst index 76ac77a75f4..12fdc125177 100644 --- a/reference/forms/types/enum.rst +++ b/reference/forms/types/enum.rst @@ -159,6 +159,8 @@ This callback will group choices in 3 categories: ``Upper``, ``Lower`` and ``Oth If you return ``null``, the option won't be grouped. +.. include:: /reference/forms/types/options/duplicate_preferred_choices.rst.inc + .. include:: /reference/forms/types/options/multiple.rst.inc .. include:: /reference/forms/types/options/placeholder.rst.inc diff --git a/reference/forms/types/language.rst b/reference/forms/types/language.rst index 8b301826b85..2ed8e3c402a 100644 --- a/reference/forms/types/language.rst +++ b/reference/forms/types/language.rst @@ -85,6 +85,8 @@ Inherited Options These options inherit from the :doc:`ChoiceType `: +.. include:: /reference/forms/types/options/duplicate_preferred_choices.rst.inc + .. include:: /reference/forms/types/options/error_bubbling.rst.inc .. include:: /reference/forms/types/options/error_mapping.rst.inc diff --git a/reference/forms/types/locale.rst b/reference/forms/types/locale.rst index 23fafe9304f..59794c7ba4c 100644 --- a/reference/forms/types/locale.rst +++ b/reference/forms/types/locale.rst @@ -62,6 +62,8 @@ Inherited Options These options inherit from the :doc:`ChoiceType `: +.. include:: /reference/forms/types/options/duplicate_preferred_choices.rst.inc + .. include:: /reference/forms/types/options/error_bubbling.rst.inc .. include:: /reference/forms/types/options/error_mapping.rst.inc diff --git a/reference/forms/types/options/duplicate_preferred_choices.rst.inc b/reference/forms/types/options/duplicate_preferred_choices.rst.inc new file mode 100644 index 00000000000..9d6d3c94a49 --- /dev/null +++ b/reference/forms/types/options/duplicate_preferred_choices.rst.inc @@ -0,0 +1,27 @@ +``duplicate_preferred_choices`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +**type**: ``boolean`` **default**: ``true`` + +When using the ``preferred_choices`` option, the selected choices are displayed +twice by default: at the top of your list and in the complete list. You can +change this behavior: when setting this option to ``false``, preferred choices +will only be displayed at the top of the list. + + use Symfony\Component\Form\Extension\Core\Type\ChoiceType; + // ... + + $builder->add('language', ChoiceType::class, [ + 'choices' => [ + 'English' => 'en', + 'Spanish' => 'es', + 'Bork' => 'muppets', + 'Pirate' => 'arr', + ], + 'preferred_choices' => ['muppets', 'arr'], + 'duplicate_preferred_choices' => false, + ]); + +.. versionadded:: 6.4 + + The ``duplicate_preferred_choices`` option was introduced in Symfony 6.4. diff --git a/reference/forms/types/timezone.rst b/reference/forms/types/timezone.rst index 1ccb99ac611..a6564855a92 100644 --- a/reference/forms/types/timezone.rst +++ b/reference/forms/types/timezone.rst @@ -83,6 +83,8 @@ Inherited Options These options inherit from the :doc:`ChoiceType `: +.. include:: /reference/forms/types/options/duplicate_preferred_choices.rst.inc + .. include:: /reference/forms/types/options/expanded.rst.inc .. include:: /reference/forms/types/options/multiple.rst.inc