From 6421462a9acfda36b576a2b8aedfb1209c9dc21b Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 3 Jan 2020 19:23:58 +0100 Subject: [PATCH 1/2] do not render preferred choices as selected --- .../views/Form/form_div_layout.html.twig | 4 ++- .../views/Form/foundation_5_layout.html.twig | 2 ++ .../AbstractBootstrap3LayoutTest.php | 25 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Resources/views/Form/form_div_layout.html.twig b/Resources/views/Form/form_div_layout.html.twig index a97a38e5..b5f1d36c 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 -%} diff --git a/Resources/views/Form/foundation_5_layout.html.twig b/Resources/views/Form/foundation_5_layout.html.twig index 83c5e30d..e5d12973 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 66654d9c..b46358d6 100644 --- a/Tests/Extension/AbstractBootstrap3LayoutTest.php +++ b/Tests/Extension/AbstractBootstrap3LayoutTest.php @@ -531,6 +531,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', [ From 60ba4c54c064649735708d46e3a1c06ade0ff838 Mon Sep 17 00:00:00 2001 From: Stephen Lewis Date: Fri, 3 Jan 2020 11:56:12 +0000 Subject: [PATCH 2/2] [TwigBridge] button_widget now has its title attr translated even if its label = null or false --- Resources/views/Form/form_div_layout.html.twig | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Resources/views/Form/form_div_layout.html.twig b/Resources/views/Form/form_div_layout.html.twig index ad4477cb..cee716eb 100644 --- a/Resources/views/Form/form_div_layout.html.twig +++ b/Resources/views/Form/form_div_layout.html.twig @@ -222,13 +222,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 -%}