Skip to content

[Form] repeat preferred choices in list of all choices #32658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ public function testPreferredChoices()
]);

$this->assertEquals([3 => new ChoiceView($entity3, '3', 'Baz'), 2 => new ChoiceView($entity2, '2', 'Bar')], $field->createView()->vars['preferred_choices']);
$this->assertEquals([1 => new ChoiceView($entity1, '1', 'Foo')], $field->createView()->vars['choices']);
$this->assertEquals([1 => new ChoiceView($entity1, '1', 'Foo'), 2 => new ChoiceView($entity2, '2', 'Bar'), 3 => new ChoiceView($entity3, '3', 'Baz')], $field->createView()->vars['choices']);
}

public function testOverrideChoicesWithPreferredChoices()
Expand All @@ -868,7 +868,7 @@ public function testOverrideChoicesWithPreferredChoices()
]);

$this->assertEquals([3 => new ChoiceView($entity3, '3', 'Baz')], $field->createView()->vars['preferred_choices']);
$this->assertEquals([2 => new ChoiceView($entity2, '2', 'Bar')], $field->createView()->vars['choices']);
$this->assertEquals([2 => new ChoiceView($entity2, '2', 'Bar'), 3 => new ChoiceView($entity3, '3', 'Baz')], $field->createView()->vars['choices']);
}

public function testDisallowChoicesThatAreNotIncludedChoicesSingleIdentifier()
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Doctrine/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"symfony/stopwatch": "^3.4|^4.0|^5.0",
"symfony/config": "^4.2|^5.0",
"symfony/dependency-injection": "^3.4|^4.0|^5.0",
"symfony/form": "^4.3|^5.0",
"symfony/form": "^4.4|^5.0",
"symfony/http-kernel": "^3.4|^4.0|^5.0",
"symfony/messenger": "^4.3|^5.0",
"symfony/property-access": "^3.4|^4.0|^5.0",
Expand All @@ -48,7 +48,7 @@
"conflict": {
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0",
"symfony/dependency-injection": "<3.4",
"symfony/form": "<4.3",
"symfony/form": "<4.4",
"symfony/messenger": "<4.3"
},
"suggest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,9 @@ public function testSingleChoiceWithPreferred()
./option[@value="&b"][not(@selected)][.="[trans]Choice&B[/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)=3]
[count(./option)=4]
'
);
}
Expand All @@ -547,8 +548,9 @@ public function testSingleChoiceWithPreferredAndNoSeparator()
[
./option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
/following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
/following-sibling::option[@value="&b"][.="[trans]Choice&B[/trans]"]
]
[count(./option)=2]
[count(./option)=3]
'
);
}
Expand All @@ -571,8 +573,9 @@ public function testSingleChoiceWithPreferredAndBlankSeparator()
./option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
/following-sibling::option[@disabled="disabled"][not(@selected)][.=""]
/following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
/following-sibling::option[@value="&b"][.="[trans]Choice&B[/trans]"]
]
[count(./option)=3]
[count(./option)=4]
'
);
}
Expand All @@ -589,7 +592,7 @@ public function testChoiceWithOnlyPreferred()
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
'/select
[@class="my&class form-control"]
[count(./option)=2]
[count(./option)=5]
'
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Twig/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"symfony/asset": "^3.4|^4.0|^5.0",
"symfony/dependency-injection": "^3.4|^4.0|^5.0",
"symfony/finder": "^3.4|^4.0|^5.0",
"symfony/form": "^4.3|^5.0",
"symfony/form": "^4.4|^5.0",
"symfony/http-foundation": "^4.3|^5.0",
"symfony/http-kernel": "^3.4|^4.0|^5.0",
"symfony/mime": "^4.3|^5.0",
Expand All @@ -46,7 +46,7 @@
},
"conflict": {
"symfony/console": "<3.4",
"symfony/form": "<4.3",
"symfony/form": "<4.4",
"symfony/http-foundation": "<4.3",
"symfony/translation": "<4.2",
"symfony/workflow": "<4.3"
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
4.4.0
-----

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

4.3.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ private static function addChoiceView($choice, $value, $label, $keys, &$index, $
if ($isPreferred && false !== $preferredKey = $isPreferred($choice, $key, $value)) {
$preferredViews[$nextIndex] = $view;
$preferredViewsOrder[$nextIndex] = $preferredKey;
} else {
$otherViews[$nextIndex] = $view;
}

$otherViews[$nextIndex] = $view;
}

private static function addChoiceViewsFromStructuredValues($values, $label, $choices, $keys, &$index, $attr, $isPreferred, &$preferredViews, &$preferredViewsOrder, &$otherViews)
Expand Down
11 changes: 7 additions & 4 deletions src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,9 @@ public function testSingleChoiceWithPreferred()
./option[@value="&b"][not(@selected)][.="[trans]Choice&B[/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)=3]
[count(./option)=4]
'
);
}
Expand All @@ -763,8 +764,9 @@ public function testSingleChoiceWithPreferredAndNoSeparator()
[
./option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
/following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
/following-sibling::option[@value="&b"][.="[trans]Choice&B[/trans]"]
]
[count(./option)=2]
[count(./option)=3]
'
);
}
Expand All @@ -786,8 +788,9 @@ public function testSingleChoiceWithPreferredAndBlankSeparator()
./option[@value="&b"][not(@selected)][.="[trans]Choice&B[/trans]"]
/following-sibling::option[@disabled="disabled"][not(@selected)][.=""]
/following-sibling::option[@value="&a"][@selected="selected"][.="[trans]Choice&A[/trans]"]
/following-sibling::option[@value="&b"][.="[trans]Choice&B[/trans]"]
]
[count(./option)=3]
[count(./option)=4]
'
);
}
Expand All @@ -803,7 +806,7 @@ public function testChoiceWithOnlyPreferred()

$this->assertWidgetMatchesXpath($form->createView(), [],
'/select
[count(./option)=2]
[count(./option)=5]
'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,8 @@ private function assertFlatView($view)
$this->assertEquals(new ChoiceListView(
[
0 => new ChoiceView($this->obj1, '0', 'A'),
1 => new ChoiceView($this->obj2, '1', 'B'),
2 => new ChoiceView($this->obj3, '2', 'C'),
3 => new ChoiceView($this->obj4, '3', 'D'),
], [
1 => new ChoiceView($this->obj2, '1', 'B'),
Expand All @@ -752,6 +754,8 @@ private function assertFlatViewWithCustomIndices($view)
$this->assertEquals(new ChoiceListView(
[
'w' => new ChoiceView($this->obj1, '0', 'A'),
'x' => new ChoiceView($this->obj2, '1', 'B'),
'y' => new ChoiceView($this->obj3, '2', 'C'),
'z' => new ChoiceView($this->obj4, '3', 'D'),
], [
'x' => new ChoiceView($this->obj2, '1', 'B'),
Expand All @@ -765,6 +769,18 @@ private function assertFlatViewWithAttr($view)
$this->assertEquals(new ChoiceListView(
[
0 => new ChoiceView($this->obj1, '0', 'A'),
1 => new ChoiceView(
$this->obj2,
'1',
'B',
['attr1' => 'value1']
),
2 => new ChoiceView(
$this->obj3,
'2',
'C',
['attr2' => 'value2']
),
3 => new ChoiceView($this->obj4, '3', 'D'),
], [
1 => new ChoiceView(
Expand All @@ -789,11 +805,17 @@ private function assertGroupedView($view)
[
'Group 1' => new ChoiceGroupView(
'Group 1',
[0 => new ChoiceView($this->obj1, '0', 'A')]
[
0 => new ChoiceView($this->obj1, '0', 'A'),
1 => new ChoiceView($this->obj2, '1', 'B'),
]
),
'Group 2' => new ChoiceGroupView(
'Group 2',
[3 => new ChoiceView($this->obj4, '3', 'D')]
[
2 => new ChoiceView($this->obj3, '2', 'C'),
3 => new ChoiceView($this->obj4, '3', 'D'),
]
),
], [
'Group 1' => new ChoiceGroupView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,9 @@ public function testPassPreferredChoicesToView()

$this->assertEquals([
0 => new ChoiceView('a', 'a', 'A'),
1 => new ChoiceView('b', 'b', 'B'),
2 => new ChoiceView('c', 'c', 'C'),
3 => new ChoiceView('d', 'd', 'D'),
], $view->vars['choices']);
$this->assertEquals([
1 => new ChoiceView('b', 'b', 'B'),
Expand All @@ -1750,9 +1752,11 @@ public function testPassHierarchicalChoicesToView()
$this->assertEquals([
'Symfony' => new ChoiceGroupView('Symfony', [
0 => new ChoiceView('a', 'a', 'Bernhard'),
1 => new ChoiceView('b', 'b', 'Fabien'),
2 => new ChoiceView('c', 'c', 'Kris'),
]),
'Doctrine' => new ChoiceGroupView('Doctrine', [
3 => new ChoiceView('d', 'd', 'Jon'),
4 => new ChoiceView('e', 'e', 'Roman'),
]),
], $view->vars['choices']);
Expand Down