diff --git a/Resources/views/Form/form_div_layout.html.twig b/Resources/views/Form/form_div_layout.html.twig
index a97a38e5..45843e71 100644
--- a/Resources/views/Form/form_div_layout.html.twig
+++ b/Resources/views/Form/form_div_layout.html.twig
@@ -65,12 +65,14 @@
{%- endif -%}
{%- if preferred_choices|length > 0 -%}
{% set options = preferred_choices %}
+ {% set render_preferred_choices = true %}
{{- block('choice_widget_options') -}}
{%- if choices|length > 0 and separator is not none -%}
{%- endif -%}
{%- endif -%}
{%- set options = choices -%}
+ {%- set render_preferred_choices = false -%}
{{- block('choice_widget_options') -}}
{%- endblock choice_widget_collapsed -%}
@@ -83,7 +85,7 @@
{{- block('choice_widget_options') -}}
{%- else -%}
-
+
{%- endif -%}
{% endfor %}
{%- endblock choice_widget_options -%}
@@ -226,13 +228,11 @@
'%name%': name,
'%id%': id,
}) %}
- {%- elseif label is same as(false) -%}
- {% set translation_domain = false %}
- {%- else -%}
+ {%- elseif label is not same as(false) -%}
{% set label = name|humanize %}
{%- endif -%}
{%- endif -%}
-
+
{%- endblock button_widget -%}
{%- block submit_widget -%}
diff --git a/Resources/views/Form/foundation_5_layout.html.twig b/Resources/views/Form/foundation_5_layout.html.twig
index 8ab44ccc..b02b9421 100644
--- a/Resources/views/Form/foundation_5_layout.html.twig
+++ b/Resources/views/Form/foundation_5_layout.html.twig
@@ -160,12 +160,14 @@
{%- endif %}
{%- if preferred_choices|length > 0 -%}
{% set options = preferred_choices %}
+ {% set render_preferred_choices = true %}
{{- block('choice_widget_options') -}}
{% if choices|length > 0 and separator is not none -%}
{%- endif %}
{%- endif -%}
{% set options = choices -%}
+ {%- set render_preferred_choices = false -%}
{{- block('choice_widget_options') -}}
{%- endblock choice_widget_collapsed %}
diff --git a/Tests/Extension/AbstractBootstrap3LayoutTest.php b/Tests/Extension/AbstractBootstrap3LayoutTest.php
index ff5c677c..8504f8b7 100644
--- a/Tests/Extension/AbstractBootstrap3LayoutTest.php
+++ b/Tests/Extension/AbstractBootstrap3LayoutTest.php
@@ -546,6 +546,31 @@ public function testSingleChoiceWithPreferred()
);
}
+ public function testSingleChoiceWithSelectedPreferred()
+ {
+ $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', [
+ 'choices' => ['Choice&A' => '&a', 'Choice&B' => '&b'],
+ 'preferred_choices' => ['&a'],
+ 'multiple' => false,
+ 'expanded' => false,
+ ]);
+
+ $this->assertWidgetMatchesXpath($form->createView(), ['separator' => '-- sep --', 'attr' => ['class' => 'my&class']],
+'/select
+ [@name="name"]
+ [@class="my&class form-control"]
+ [not(@required)]
+ [
+ ./option[@value="&a"][not(@selected)][.="[trans]Choice&A[/trans]"]
+ /following-sibling::option[@disabled="disabled"][not(@selected)][.="-- sep --"]
+ /following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
+ /following-sibling::option[@value="&b"][.="[trans]Choice&B[/trans]"]
+ ]
+ [count(./option)=4]
+'
+ );
+ }
+
public function testSingleChoiceWithPreferredAndNoSeparator()
{
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', [