diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
index 29cfc2dc62e9f..d57a4e1197e1e 100644
--- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
+++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
@@ -68,7 +68,11 @@
{% set render_preferred_choices = true %}
{{- block('choice_widget_options') -}}
{%- if choices|length > 0 and separator is not none -%}
-
+ {%- if separator_html is not defined or separator_html is same as(false) -%}
+
+ {% else %}
+ {{ separator|raw }}
+ {% endif %}
{%- endif -%}
{%- endif -%}
{%- set options = choices -%}
diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/foundation_5_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/foundation_5_layout.html.twig
index 4040f9a79d427..fe5af460226fa 100644
--- a/src/Symfony/Bridge/Twig/Resources/views/Form/foundation_5_layout.html.twig
+++ b/src/Symfony/Bridge/Twig/Resources/views/Form/foundation_5_layout.html.twig
@@ -163,7 +163,11 @@
{% set render_preferred_choices = true %}
{{- block('choice_widget_options') -}}
{% if choices|length > 0 and separator is not none -%}
-
+ {%- if separator_html is not defined or separator_html is same as(false) -%}
+
+ {% else %}
+ {{ separator|raw }}
+ {% endif %}
{%- endif %}
{%- endif -%}
{% set options = choices -%}
diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md
index 273a71c0cde51..eb374a589df05 100644
--- a/src/Symfony/Component/Form/CHANGELOG.md
+++ b/src/Symfony/Component/Form/CHANGELOG.md
@@ -4,6 +4,7 @@ CHANGELOG
7.1
---
+ * Add option `separator` to `ChoiceType` to use a custom separator after preferred choices (use the new `separator_html` option to display the separator text as HTML)
* Deprecate not configuring the `default_protocol` option of the `UrlType`, it will default to `null` in 8.0
7.0
diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
index 0030a835ff636..8d4584761c402 100644
--- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
+++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
@@ -234,7 +234,8 @@ public function buildView(FormView $view, FormInterface $form, array $options):
'expanded' => $options['expanded'],
'preferred_choices' => $choiceListView->preferredChoices,
'choices' => $choiceListView->choices,
- 'separator' => '-------------------',
+ 'separator' => $options['separator'],
+ 'separator_html' => $options['separator_html'],
'placeholder' => null,
'placeholder_attr' => [],
'choice_translation_domain' => $choiceTranslationDomain,
@@ -342,6 +343,8 @@ public function configureOptions(OptionsResolver $resolver): void
'choice_attr' => null,
'choice_translation_parameters' => [],
'preferred_choices' => [],
+ 'separator' => '-------------------',
+ 'separator_html' => false,
'duplicate_preferred_choices' => true,
'group_by' => null,
'empty_data' => $emptyData,
@@ -372,6 +375,8 @@ public function configureOptions(OptionsResolver $resolver): void
$resolver->setAllowedTypes('choice_translation_parameters', ['null', 'array', 'callable', ChoiceTranslationParameters::class]);
$resolver->setAllowedTypes('placeholder_attr', ['array']);
$resolver->setAllowedTypes('preferred_choices', ['array', \Traversable::class, 'callable', 'string', PropertyPath::class, PreferredChoice::class]);
+ $resolver->setAllowedTypes('separator', ['string']);
+ $resolver->setAllowedTypes('separator_html', ['bool']);
$resolver->setAllowedTypes('duplicate_preferred_choices', 'bool');
$resolver->setAllowedTypes('group_by', ['null', 'callable', 'string', PropertyPath::class, GroupBy::class]);
}
diff --git a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.json b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.json
index 27371fd6f668a..e071ec712fa13 100644
--- a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.json
+++ b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.json
@@ -18,7 +18,9 @@
"multiple",
"placeholder",
"placeholder_attr",
- "preferred_choices"
+ "preferred_choices",
+ "separator",
+ "separator_html"
],
"overridden": {
"Symfony\\Component\\Form\\Extension\\Core\\Type\\FormType": [
diff --git a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.txt b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.txt
index c8aee5e783270..005bfd3e96350 100644
--- a/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.txt
+++ b/src/Symfony/Component/Form/Tests/Fixtures/Descriptor/resolved_form_type_1.txt
@@ -21,8 +21,8 @@ Symfony\Component\Form\Extension\Core\Type\ChoiceType (Block prefix: "choice")
placeholder getter
placeholder_attr help
preferred_choices help_attr
- help_html
- help_translation_parameters
+ separator help_html
+ separator_html help_translation_parameters
inherit_data
invalid_message_parameters
is_empty_callback