Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 909d2b9

Browse filesBrowse files
[Form] Swap new ChoiceView constructor arguments to ease migrating from the deprecated one
1 parent d1404a6 commit 909d2b9
Copy full SHA for 909d2b9

File tree

Expand file treeCollapse file tree

17 files changed

+106
-123
lines changed
Filter options
Expand file treeCollapse file tree

17 files changed

+106
-123
lines changed

‎UPGRADE-2.7.md

Copy file name to clipboardExpand all lines: UPGRADE-2.7.md
+2-18Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -176,24 +176,8 @@ Form
176176
* `Symfony\Component\Form\Extension\Core\ChoiceList\View\ChoiceView` was
177177
deprecated and will be removed in Symfony 3.0. You should use
178178
`Symfony\Component\Form\ChoiceList\View\ChoiceView` instead.
179-
180-
Note that the order of the arguments passed to the constructor was inverted.
181-
182-
Before:
183-
184-
```php
185-
use Symfony\Component\Form\Extension\Core\ChoiceList\View\ChoiceView;
186-
187-
$view = new ChoiceView($data, 'value', 'Label');
188-
```
189-
190-
After:
191-
192-
```php
193-
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
194-
195-
$view = new ChoiceView('Label', 'value', $data);
196-
```
179+
The constructor arguments of the new class are in the same order than in the
180+
deprecated one (this was not true in 2.7.0 but has been fixed in 2.7.1).
197181

198182
* `Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList` was
199183
deprecated and will be removed in Symfony 3.0. You should use

‎src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php
+13-13Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function testSetDataToUninitializedEntityWithNonRequired()
134134
'choice_label' => 'name',
135135
));
136136

137-
$this->assertEquals(array(1 => new ChoiceView('Foo', '1', $entity1), 2 => new ChoiceView('Bar', '2', $entity2)), $field->createView()->vars['choices']);
137+
$this->assertEquals(array(1 => new ChoiceView($entity1, '1', 'Foo'), 2 => new ChoiceView($entity2, '2', 'Bar')), $field->createView()->vars['choices']);
138138
}
139139

140140
public function testSetDataToUninitializedEntityWithNonRequiredToString()
@@ -150,7 +150,7 @@ public function testSetDataToUninitializedEntityWithNonRequiredToString()
150150
'required' => false,
151151
));
152152

153-
$this->assertEquals(array(1 => new ChoiceView('Foo', '1', $entity1), 2 => new ChoiceView('Bar', '2', $entity2)), $field->createView()->vars['choices']);
153+
$this->assertEquals(array(1 => new ChoiceView($entity1, '1', 'Foo'), 2 => new ChoiceView($entity2, '2', 'Bar')), $field->createView()->vars['choices']);
154154
}
155155

156156
public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder()
@@ -169,7 +169,7 @@ public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder()
169169
'query_builder' => $qb,
170170
));
171171

172-
$this->assertEquals(array(1 => new ChoiceView('Foo', '1', $entity1), 2 => new ChoiceView('Bar', '2', $entity2)), $field->createView()->vars['choices']);
172+
$this->assertEquals(array(1 => new ChoiceView($entity1, '1', 'Foo'), 2 => new ChoiceView($entity2, '2', 'Bar')), $field->createView()->vars['choices']);
173173
}
174174

175175
/**
@@ -513,7 +513,7 @@ public function testOverrideChoices()
513513

514514
$field->submit('2');
515515

516-
$this->assertEquals(array(1 => new ChoiceView('Foo', '1', $entity1), 2 => new ChoiceView('Bar', '2', $entity2)), $field->createView()->vars['choices']);
516+
$this->assertEquals(array(1 => new ChoiceView($entity1, '1', 'Foo'), 2 => new ChoiceView($entity2, '2', 'Bar')), $field->createView()->vars['choices']);
517517
$this->assertTrue($field->isSynchronized());
518518
$this->assertSame($entity2, $field->getData());
519519
$this->assertSame('2', $field->getViewData());
@@ -541,13 +541,13 @@ public function testGroupByChoices()
541541
$this->assertSame('2', $field->getViewData());
542542
$this->assertEquals(array(
543543
'Group1' => new ChoiceGroupView('Group1', array(
544-
1 => new ChoiceView('Foo', '1', $item1),
545-
2 => new ChoiceView('Bar', '2', $item2),
544+
1 => new ChoiceView($item1, '1', 'Foo'),
545+
2 => new ChoiceView($item2, '2', 'Bar'),
546546
)),
547547
'Group2' => new ChoiceGroupView('Group2', array(
548-
3 => new ChoiceView('Baz', '3', $item3),
548+
3 => new ChoiceView($item3, '3', 'Baz'),
549549
)),
550-
4 => new ChoiceView('Boo!', '4', $item4),
550+
4 => new ChoiceView($item4, '4', 'Boo!'),
551551
), $field->createView()->vars['choices']);
552552
}
553553

@@ -566,8 +566,8 @@ public function testPreferredChoices()
566566
'choice_label' => 'name',
567567
));
568568

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

573573
public function testOverrideChoicesWithPreferredChoices()
@@ -586,8 +586,8 @@ public function testOverrideChoicesWithPreferredChoices()
586586
'choice_label' => 'name',
587587
));
588588

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

593593
public function testDisallowChoicesThatAreNotIncludedChoicesSingleIdentifier()
@@ -883,7 +883,7 @@ public function testPropertyOption()
883883
'property' => 'name',
884884
));
885885

886-
$this->assertEquals(array(1 => new ChoiceView('Foo', '1', $entity1), 2 => new ChoiceView('Bar', '2', $entity2)), $field->createView()->vars['choices']);
886+
$this->assertEquals(array(1 => new ChoiceView($entity1, '1', 'Foo'), 2 => new ChoiceView($entity2, '2', 'Bar')), $field->createView()->vars['choices']);
887887
}
888888

889889
protected function createRegistryMock($name, $em)

‎src/Symfony/Bridge/Doctrine/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"symfony/phpunit-bridge": "~2.7",
2424
"symfony/stopwatch": "~2.2",
2525
"symfony/dependency-injection": "~2.2",
26-
"symfony/form": "~2.7",
26+
"symfony/form": "~2.7,>=2.7.1",
2727
"symfony/http-kernel": "~2.2",
2828
"symfony/property-access": "~2.3",
2929
"symfony/security": "~2.2",

‎src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function isSelectedChoiceProvider()
136136
*/
137137
public function testIsChoiceSelected($expected, $choice, $value)
138138
{
139-
$choice = new ChoiceView($choice.' label', $choice, $choice);
139+
$choice = new ChoiceView($choice, $choice, $choice.' label');
140140

141141
$this->assertSame($expected, $this->extension->isSelectedChoice($choice, $value));
142142
}

‎src/Symfony/Bridge/Twig/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"symfony/phpunit-bridge": "~2.7",
2424
"symfony/asset": "~2.7",
2525
"symfony/finder": "~2.3",
26-
"symfony/form": "~2.7",
26+
"symfony/form": "~2.7,>=2.7.1",
2727
"symfony/http-kernel": "~2.3",
2828
"symfony/intl": "~2.3",
2929
"symfony/routing": "~2.2",

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null,
144144
if ($list instanceof LegacyChoiceListInterface && empty($preferredChoices)
145145
&& null === $label && null === $index && null === $groupBy && null === $attr) {
146146
$mapToNonLegacyChoiceView = function (LegacyChoiceView $choiceView) {
147-
return new ChoiceView($choiceView->label, $choiceView->value, $choiceView->data);
147+
return new ChoiceView($choiceView->data, $choiceView->value, $choiceView->label);
148148
};
149149

150150
return new ChoiceListView(
@@ -245,10 +245,10 @@ private static function addChoiceView($choice, $key, $label, $values, &$index, $
245245
$nextIndex = is_int($index) ? $index++ : call_user_func($index, $choice, $key, $value);
246246

247247
$view = new ChoiceView(
248+
$choice,
249+
$value,
248250
// If the labels are null, use the choice key by default
249251
null === $label ? (string) $key : (string) call_user_func($label, $choice, $key, $value),
250-
$value,
251-
$choice,
252252
// The attributes may be a callable or a mapping from choice indices
253253
// to nested arrays
254254
is_callable($attr) ? call_user_func($attr, $choice, $key, $value) : (isset($attr[$key]) ? $attr[$key] : array())

‎src/Symfony/Component/Form/ChoiceList/View/ChoiceView.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/ChoiceList/View/ChoiceView.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ class ChoiceView extends LegacyChoiceView
7878
/**
7979
* Creates a new choice view.
8080
*
81-
* @param string $label The label displayed to humans
82-
* @param string $value The view representation of the choice
8381
* @param mixed $data The original choice
82+
* @param string $value The view representation of the choice
83+
* @param string $label The label displayed to humans
8484
* @param array $attr Additional attributes for the HTML tag
8585
*/
86-
public function __construct($label, $value, $data, array $attr = array())
86+
public function __construct($data, $value, $label, array $attr = array())
8787
{
8888
parent::__construct($data, $value, $label);
8989

‎src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Component\Form\AbstractType;
1515
use Symfony\Component\Form\ChoiceList\Factory\PropertyAccessDecorator;
16-
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
1716
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
1817
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
1918
use Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory;
@@ -71,7 +70,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
7170
// Check if the choices already contain the empty value
7271
// Only add the placeholder option if this is not the case
7372
if (null !== $options['placeholder'] && 0 === count($options['choice_list']->getChoicesForValues(array('')))) {
74-
$placeholderView = new ChoiceView($options['placeholder'], '', null);
73+
$placeholderView = new ChoiceView(null, '', $options['placeholder']);
7574

7675
// "placeholder" is a reserved name
7776
$this->addSubForm($builder, 'placeholder', $placeholderView, $options);
@@ -436,7 +435,7 @@ private function createChoiceListView(ChoiceListInterface $choiceList, array $op
436435
// information from the "choices" option for creating groups
437436
if (!$options['group_by'] && $options['choices']) {
438437
$options['group_by'] = !$options['choices_as_values']
439-
? ChoiceType::flipRecursive($options['choices'])
438+
? self::flipRecursive($options['choices'])
440439
: $options['choices'];
441440
}
442441

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php
+28-28Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,10 @@ public function testCreateViewFlat()
320320

321321
$this->assertEquals(new ChoiceListView(
322322
array(
323-
0 => new ChoiceView('A', '0', $this->obj1),
324-
1 => new ChoiceView('B', '1', $this->obj2),
325-
2 => new ChoiceView('C', '2', $this->obj3),
326-
3 => new ChoiceView('D', '3', $this->obj4),
323+
0 => new ChoiceView($this->obj1, '0', 'A'),
324+
1 => new ChoiceView($this->obj2, '1', 'B'),
325+
2 => new ChoiceView($this->obj3, '2', 'C'),
326+
3 => new ChoiceView($this->obj4, '3', 'D'),
327327
), array()
328328
), $view);
329329
}
@@ -347,10 +347,10 @@ public function testCreateViewFlatPreferredChoicesEmptyArray()
347347

348348
$this->assertEquals(new ChoiceListView(
349349
array(
350-
0 => new ChoiceView('A', '0', $this->obj1),
351-
1 => new ChoiceView('B', '1', $this->obj2),
352-
2 => new ChoiceView('C', '2', $this->obj3),
353-
3 => new ChoiceView('D', '3', $this->obj4),
350+
0 => new ChoiceView($this->obj1, '0', 'A'),
351+
1 => new ChoiceView($this->obj2, '1', 'B'),
352+
2 => new ChoiceView($this->obj3, '2', 'C'),
353+
3 => new ChoiceView($this->obj4, '3', 'D'),
354354
), array()
355355
), $view);
356356
}
@@ -751,8 +751,8 @@ public function testCreateViewForLegacyChoiceList()
751751

752752
$view = $this->factory->createView($list);
753753

754-
$this->assertEquals(array(new ChoiceView('Other', 'y', 'y')), $view->choices);
755-
$this->assertEquals(array(new ChoiceView('Preferred', 'x', 'x')), $view->preferredChoices);
754+
$this->assertEquals(array(new ChoiceView('y', 'y', 'Other')), $view->choices);
755+
$this->assertEquals(array(new ChoiceView('x', 'x', 'Preferred')), $view->preferredChoices);
756756
}
757757

758758
private function assertScalarListWithGeneratedValues(ChoiceListInterface $list)
@@ -827,11 +827,11 @@ private function assertFlatView($view)
827827
{
828828
$this->assertEquals(new ChoiceListView(
829829
array(
830-
0 => new ChoiceView('A', '0', $this->obj1),
831-
3 => new ChoiceView('D', '3', $this->obj4),
830+
0 => new ChoiceView($this->obj1, '0', 'A'),
831+
3 => new ChoiceView($this->obj4, '3', 'D'),
832832
), array(
833-
1 => new ChoiceView('B', '1', $this->obj2),
834-
2 => new ChoiceView('C', '2', $this->obj3),
833+
1 => new ChoiceView($this->obj2, '1', 'B'),
834+
2 => new ChoiceView($this->obj3, '2', 'C'),
835835
)
836836
), $view);
837837
}
@@ -840,11 +840,11 @@ private function assertFlatViewWithCustomIndices($view)
840840
{
841841
$this->assertEquals(new ChoiceListView(
842842
array(
843-
'w' => new ChoiceView('A', '0', $this->obj1),
844-
'z' => new ChoiceView('D', '3', $this->obj4),
843+
'w' => new ChoiceView($this->obj1, '0', 'A'),
844+
'z' => new ChoiceView($this->obj4, '3', 'D'),
845845
), array(
846-
'x' => new ChoiceView('B', '1', $this->obj2),
847-
'y' => new ChoiceView('C', '2', $this->obj3),
846+
'x' => new ChoiceView($this->obj2, '1', 'B'),
847+
'y' => new ChoiceView($this->obj3, '2', 'C'),
848848
)
849849
), $view);
850850
}
@@ -853,19 +853,19 @@ private function assertFlatViewWithAttr($view)
853853
{
854854
$this->assertEquals(new ChoiceListView(
855855
array(
856-
0 => new ChoiceView('A', '0', $this->obj1),
857-
3 => new ChoiceView('D', '3', $this->obj4),
856+
0 => new ChoiceView($this->obj1, '0', 'A'),
857+
3 => new ChoiceView($this->obj4, '3', 'D'),
858858
), array(
859859
1 => new ChoiceView(
860-
'B',
861-
'1',
862860
$this->obj2,
861+
'1',
862+
'B',
863863
array('attr1' => 'value1')
864864
),
865865
2 => new ChoiceView(
866-
'C',
867-
'2',
868866
$this->obj3,
867+
'2',
868+
'C',
869869
array('attr2' => 'value2')
870870
),
871871
)
@@ -878,20 +878,20 @@ private function assertGroupedView($view)
878878
array(
879879
'Group 1' => new ChoiceGroupView(
880880
'Group 1',
881-
array(0 => new ChoiceView('A', '0', $this->obj1))
881+
array(0 => new ChoiceView($this->obj1, '0', 'A'))
882882
),
883883
'Group 2' => new ChoiceGroupView(
884884
'Group 2',
885-
array(3 => new ChoiceView('D', '3', $this->obj4))
885+
array(3 => new ChoiceView($this->obj4, '3', 'D'))
886886
),
887887
), array(
888888
'Group 1' => new ChoiceGroupView(
889889
'Group 1',
890-
array(1 => new ChoiceView('B', '1', $this->obj2))
890+
array(1 => new ChoiceView($this->obj2, '1', 'B'))
891891
),
892892
'Group 2' => new ChoiceGroupView(
893893
'Group 2',
894-
array(2 => new ChoiceView('C', '2', $this->obj3))
894+
array(2 => new ChoiceView($this->obj3, '2', 'C'))
895895
),
896896
)
897897
), $view);

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php
+17-17Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,10 +1556,10 @@ public function testPassChoicesToView()
15561556
$view = $form->createView();
15571557

15581558
$this->assertEquals(array(
1559-
new ChoiceView('A', 'a', 'a'),
1560-
new ChoiceView('B', 'b', 'b'),
1561-
new ChoiceView('C', 'c', 'c'),
1562-
new ChoiceView('D', 'd', 'd'),
1559+
new ChoiceView('a', 'a', 'A'),
1560+
new ChoiceView('b', 'b', 'B'),
1561+
new ChoiceView('c', 'c', 'C'),
1562+
new ChoiceView('d', 'd', 'D'),
15631563
), $view->vars['choices']);
15641564
}
15651565

@@ -1573,12 +1573,12 @@ public function testPassPreferredChoicesToView()
15731573
$view = $form->createView();
15741574

15751575
$this->assertEquals(array(
1576-
0 => new ChoiceView('A', 'a', 'a'),
1577-
2 => new ChoiceView('C', 'c', 'c'),
1576+
0 => new ChoiceView('a', 'a', 'A'),
1577+
2 => new ChoiceView('c', 'c', 'C'),
15781578
), $view->vars['choices']);
15791579
$this->assertEquals(array(
1580-
1 => new ChoiceView('B', 'b', 'b'),
1581-
3 => new ChoiceView('D', 'd', 'd'),
1580+
1 => new ChoiceView('b', 'b', 'B'),
1581+
3 => new ChoiceView('d', 'd', 'D'),
15821582
), $view->vars['preferred_choices']);
15831583
}
15841584

@@ -1592,19 +1592,19 @@ public function testPassHierarchicalChoicesToView()
15921592

15931593
$this->assertEquals(array(
15941594
'Symfony' => new ChoiceGroupView('Symfony', array(
1595-
0 => new ChoiceView('Bernhard', 'a', 'a'),
1596-
2 => new ChoiceView('Kris', 'c', 'c'),
1595+
0 => new ChoiceView('a', 'a', 'Bernhard'),
1596+
2 => new ChoiceView('c', 'c', 'Kris'),
15971597
)),
15981598
'Doctrine' => new ChoiceGroupView('Doctrine', array(
1599-
4 => new ChoiceView('Roman', 'e', 'e'),
1599+
4 => new ChoiceView('e', 'e', 'Roman'),
16001600
)),
16011601
), $view->vars['choices']);
16021602
$this->assertEquals(array(
16031603
'Symfony' => new ChoiceGroupView('Symfony', array(
1604-
1 => new ChoiceView('Fabien', 'b', 'b'),
1604+
1 => new ChoiceView('b', 'b', 'Fabien'),
16051605
)),
16061606
'Doctrine' => new ChoiceGroupView('Doctrine', array(
1607-
3 => new ChoiceView('Jon', 'd', 'd'),
1607+
3 => new ChoiceView('d', 'd', 'Jon'),
16081608
)),
16091609
), $view->vars['preferred_choices']);
16101610
}
@@ -1624,10 +1624,10 @@ public function testPassChoiceDataToView()
16241624
$view = $form->createView();
16251625

16261626
$this->assertEquals(array(
1627-
new ChoiceView('A', 'a', $obj1),
1628-
new ChoiceView('B', 'b', $obj2),
1629-
new ChoiceView('C', 'c', $obj3),
1630-
new ChoiceView('D', 'd', $obj4),
1627+
new ChoiceView($obj1, 'a', 'A'),
1628+
new ChoiceView($obj2, 'b', 'B'),
1629+
new ChoiceView($obj3, 'c', 'C'),
1630+
new ChoiceView($obj4, 'd', 'D'),
16311631
), $view->vars['choices']);
16321632
}
16331633

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.