Skip to content

Commit 1001b82

Browse files
committed
repeat preferred choices in list of all choices
1 parent 7dfc97b commit 1001b82

File tree

6 files changed

+45
-12
lines changed

6 files changed

+45
-12
lines changed

src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,9 @@ public function testSingleChoiceWithPreferred()
524524
./option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
525525
/following-sibling::option[@disabled="disabled"][not(@selected)][.="-- sep --"]
526526
/following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
527+
/following-sibling::option[@value="&b"][.="[trans]Choice&B[/trans]"]
527528
]
528-
[count(./option)=3]
529+
[count(./option)=4]
529530
'
530531
);
531532
}
@@ -547,8 +548,9 @@ public function testSingleChoiceWithPreferredAndNoSeparator()
547548
[
548549
./option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
549550
/following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
551+
/following-sibling::option[@value="&b"][.="[trans]Choice&B[/trans]"]
550552
]
551-
[count(./option)=2]
553+
[count(./option)=3]
552554
'
553555
);
554556
}
@@ -571,8 +573,9 @@ public function testSingleChoiceWithPreferredAndBlankSeparator()
571573
./option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
572574
/following-sibling::option[@disabled="disabled"][not(@selected)][.=""]
573575
/following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
576+
/following-sibling::option[@value="&b"][.="[trans]Choice&B[/trans]"]
574577
]
575-
[count(./option)=3]
578+
[count(./option)=4]
576579
'
577580
);
578581
}
@@ -589,7 +592,7 @@ public function testChoiceWithOnlyPreferred()
589592
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
590593
'/select
591594
[@class="my&class form-control"]
592-
[count(./option)=2]
595+
[count(./option)=5]
593596
'
594597
);
595598
}

src/Symfony/Component/Form/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
4.4.0
55
-----
66

7+
* preferred choices are repeated in the list of all choices
78
* deprecated using `int` or `float` as data for the `NumberType` when the `input` option is set to `string`
89

910
4.3.0

src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ private static function addChoiceView($choice, $value, $label, $keys, &$index, $
157157
if ($isPreferred && false !== $preferredKey = $isPreferred($choice, $key, $value)) {
158158
$preferredViews[$nextIndex] = $view;
159159
$preferredViewsOrder[$nextIndex] = $preferredKey;
160-
} else {
161-
$otherViews[$nextIndex] = $view;
162160
}
161+
162+
$otherViews[$nextIndex] = $view;
163163
}
164164

165165
private static function addChoiceViewsFromStructuredValues($values, $label, $choices, $keys, &$index, $attr, $isPreferred, &$preferredViews, &$preferredViewsOrder, &$otherViews)

src/Symfony/Component/Form/Tests/AbstractLayoutTest.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,9 @@ public function testSingleChoiceWithPreferred()
741741
./option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
742742
/following-sibling::option[@disabled="disabled"][not(@selected)][.="-- sep --"]
743743
/following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
744+
/following-sibling::option[@value="&b"][.="[trans]Choice&B[/trans]"]
744745
]
745-
[count(./option)=3]
746+
[count(./option)=4]
746747
'
747748
);
748749
}
@@ -763,8 +764,9 @@ public function testSingleChoiceWithPreferredAndNoSeparator()
763764
[
764765
./option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
765766
/following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
767+
/following-sibling::option[@value="&b"][.="[trans]Choice&B[/trans]"]
766768
]
767-
[count(./option)=2]
769+
[count(./option)=3]
768770
'
769771
);
770772
}
@@ -786,8 +788,9 @@ public function testSingleChoiceWithPreferredAndBlankSeparator()
786788
./option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
787789
/following-sibling::option[@disabled="disabled"][not(@selected)][.=""]
788790
/following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
791+
/following-sibling::option[@value="&b"][.="[trans]Choice&B[/trans]"]
789792
]
790-
[count(./option)=3]
793+
[count(./option)=4]
791794
'
792795
);
793796
}
@@ -803,7 +806,7 @@ public function testChoiceWithOnlyPreferred()
803806

804807
$this->assertWidgetMatchesXpath($form->createView(), [],
805808
'/select
806-
[count(./option)=2]
809+
[count(./option)=5]
807810
'
808811
);
809812
}

src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php

+24-2
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,8 @@ private function assertFlatView($view)
739739
$this->assertEquals(new ChoiceListView(
740740
[
741741
0 => new ChoiceView($this->obj1, '0', 'A'),
742+
1 => new ChoiceView($this->obj2, '1', 'B'),
743+
2 => new ChoiceView($this->obj3, '2', 'C'),
742744
3 => new ChoiceView($this->obj4, '3', 'D'),
743745
], [
744746
1 => new ChoiceView($this->obj2, '1', 'B'),
@@ -752,6 +754,8 @@ private function assertFlatViewWithCustomIndices($view)
752754
$this->assertEquals(new ChoiceListView(
753755
[
754756
'w' => new ChoiceView($this->obj1, '0', 'A'),
757+
'x' => new ChoiceView($this->obj2, '1', 'B'),
758+
'y' => new ChoiceView($this->obj3, '2', 'C'),
755759
'z' => new ChoiceView($this->obj4, '3', 'D'),
756760
], [
757761
'x' => new ChoiceView($this->obj2, '1', 'B'),
@@ -765,6 +769,18 @@ private function assertFlatViewWithAttr($view)
765769
$this->assertEquals(new ChoiceListView(
766770
[
767771
0 => new ChoiceView($this->obj1, '0', 'A'),
772+
1 => new ChoiceView(
773+
$this->obj2,
774+
'1',
775+
'B',
776+
['attr1' => 'value1']
777+
),
778+
2 => new ChoiceView(
779+
$this->obj3,
780+
'2',
781+
'C',
782+
['attr2' => 'value2']
783+
),
768784
3 => new ChoiceView($this->obj4, '3', 'D'),
769785
], [
770786
1 => new ChoiceView(
@@ -789,11 +805,17 @@ private function assertGroupedView($view)
789805
[
790806
'Group 1' => new ChoiceGroupView(
791807
'Group 1',
792-
[0 => new ChoiceView($this->obj1, '0', 'A')]
808+
[
809+
0 => new ChoiceView($this->obj1, '0', 'A'),
810+
1 => new ChoiceView($this->obj2, '1', 'B'),
811+
]
793812
),
794813
'Group 2' => new ChoiceGroupView(
795814
'Group 2',
796-
[3 => new ChoiceView($this->obj4, '3', 'D')]
815+
[
816+
2 => new ChoiceView($this->obj3, '2', 'C'),
817+
3 => new ChoiceView($this->obj4, '3', 'D'),
818+
]
797819
),
798820
], [
799821
'Group 1' => new ChoiceGroupView(

src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,9 @@ public function testPassPreferredChoicesToView()
17311731

17321732
$this->assertEquals([
17331733
0 => new ChoiceView('a', 'a', 'A'),
1734+
1 => new ChoiceView('b', 'b', 'B'),
17341735
2 => new ChoiceView('c', 'c', 'C'),
1736+
3 => new ChoiceView('d', 'd', 'D'),
17351737
], $view->vars['choices']);
17361738
$this->assertEquals([
17371739
1 => new ChoiceView('b', 'b', 'B'),
@@ -1750,9 +1752,11 @@ public function testPassHierarchicalChoicesToView()
17501752
$this->assertEquals([
17511753
'Symfony' => new ChoiceGroupView('Symfony', [
17521754
0 => new ChoiceView('a', 'a', 'Bernhard'),
1755+
1 => new ChoiceView('b', 'b', 'Fabien'),
17531756
2 => new ChoiceView('c', 'c', 'Kris'),
17541757
]),
17551758
'Doctrine' => new ChoiceGroupView('Doctrine', [
1759+
3 => new ChoiceView('d', 'd', 'Jon'),
17561760
4 => new ChoiceView('e', 'e', 'Roman'),
17571761
]),
17581762
], $view->vars['choices']);

0 commit comments

Comments
 (0)