8000 [Form] Reversed the order of $type and $name in FormFactory::createNa… · haygus/symfony@877d8f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 877d8f7

Browse files
committed
[Form] Reversed the order of $type and $name in FormFactory::createNamed[Builder]()
1 parent 33fecca commit 877d8f7

19 files changed

+247
-229
lines changed

UPGRADE-2.1.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,23 @@
700700
});
701701
```
702702
703+
* The order of the first two arguments of the methods `createNamed` and
704+
`createNamedBuilder` in `FormFactoryInterface` was reversed to match with
705+
the rest of the component. You should scan your code for occurrences of
706+
these methods and reverse the parameters.
707+
708+
Before:
709+
710+
```
711+
$form = $factory->createNamed('text', 'firstName');
712+
```
713+
714+
After:
715+
716+
```
717+
$form = $factory->createNamed('firstName', 'text');
718+
```
719+
703720
### Validator
704721
705722
* The methods `setMessage()`, `getMessageTemplate()` and

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

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function testSetDataToUninitializedEntityWithNonRequired()
108108

109109
$this->persist(array($entity1, $entity2));
110110

111-
$field = $this->factory->createNamed('entity', 'name', null, array(
111+
$field = $this->factory->createNamed('name', 'entity', null, array(
112112
'em' => 'default',
113113
'class' => self::SINGLE_IDENT_CLASS,
114114
'required' => false,
@@ -125,7 +125,7 @@ public function testSetDataToUninitializedEntityWithNonRequiredToString()
125125

126126
$this->persist(array($entity1, $entity2));
127127

128-
$field = $this->factory->createNamed('entity', 'name', null, array(
128+
$field = $this->factory->createNamed('name', 'entity', null, array(
129129
'em' => 'default',
130130
'class' => self::SINGLE_IDENT_CLASS,
131131
'required' => false,
@@ -142,7 +142,7 @@ public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder()
142142
$this->persist(array($entity1, $entity2));
143143
$qb = $this->em->createQueryBuilder()->select('e')->from(self::SINGLE_IDENT_CLASS, 'e');
144144

145-
$field = $this->factory->createNamed('entity', 'name', null, array(
145+
$field = $this->factory->createNamed('name', 'entity', null, array(
146146
'em' => 'default',
147147
'class' => self::SINGLE_IDENT_CLASS,
148148
'required' => false,
@@ -158,7 +158,7 @@ public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder()
158158
*/
159159
public function testConfigureQueryBuilderWithNonQueryBuilderAndNonClosure()
160160
{
161-
$field = $this->factory->createNamed('entity', 'name', null, array(
161+
$field = $this->factory->createNamed('name', 'entity', null, array(
162162
'em' => 'default',
163163
'class' => self::SINGLE_IDENT_CLASS,
164164
'query_builder' => new \stdClass(),
@@ -170,7 +170,7 @@ public function testConfigureQueryBuilderWithNonQueryBuilderAndNonClosure()
170170
*/
171171
public function testConfigureQueryBuilderWithClosureReturningNonQueryBuilder()
172172
{
173-
$field = $this->factory->createNamed('entity', 'name', null, array(
173+
$field = $this->factory->createNamed('name', 'entity', null, array(
174174
'em' => 'default',
175175
'class' => self::SINGLE_IDENT_CLASS,
176176
'query_builder' => function () {
@@ -183,7 +183,7 @@ public function testConfigureQueryBuilderWithClosureReturningNonQueryBuilder()
183183

184184
public function testSetDataSingleNull()
185185
{
186-
$field = $this->factory->createNamed('entity', 'name', null, array(
186+
$field = $this->factory->createNamed('name', 'entity', null, array(
187187
'multiple' => false,
188188
'em' => 'default',
189189
'class' => self::SINGLE_IDENT_CLASS,
@@ -196,7 +196,7 @@ public function testSetDataSingleNull()
196196

197197
public function testSetDataMultipleExpandedNull()
198198
{
199-
$field = $this->factory->createNamed('entity', 'name', null, array(
199+
$field = $this->factory->createNamed('name', 'entity', null, array(
200200
'multiple' => true,
201201
'expanded' => true,
202202
'em' => 'default',
@@ -210,7 +210,7 @@ public function testSetDataMultipleExpandedNull()
210210

211211
public function testSetDataMultipleNonExpandedNull()
212212
{
213-
$field = $this->factory->createNamed('entity', 'name', null, array(
213+
$field = $this->factory->createNamed('name', 'entity', null, array(
214214
'multiple' => true,
215215
'expanded' => false,
216216
'em' => 'default',
@@ -224,7 +224,7 @@ public function testSetDataMultipleNonExpandedNull()
224224

225225
public function testSubmitSingleExpandedNull()
226226
{
227-
$field = $this->factory->createNamed('entity', 'name', null, array(
227+
$field = $this->factory->createNamed('name', 'entity', null, array(
228228
'multiple' => false,
229229
'expanded' => true,
230230
'em' => 'default',
@@ -238,7 +238,7 @@ public function testSubmitSingleExpandedNull()
238238

239239
public function testSubmitSingleNonExpandedNull()
240240
{
241-
$field = $this->factory->createNamed('entity', 'name', null, array(
241+
$field = $this->factory-> 6D4E createNamed('name', 'entity', null, array(
242242
'multiple' => false,
243243
'expanded' => false,
244244
'em' => 'default',
@@ -252,7 +252,7 @@ public function testSubmitSingleNonExpandedNull()
252252

253253
public function testSubmitMultipleNull()
254254
{
255-
$field = $this->factory->createNamed('entity', 'name', null, array(
255+
$field = $this->factory->createNamed('name', 'entity', null, array(
256256
'multiple' => true,
257257
'em' => 'default',
258258
'class' => self::SINGLE_IDENT_CLASS,
@@ -270,7 +270,7 @@ public function testSubmitSingleNonExpandedSingleIdentifier()
270270

271271
$this->persist(array($entity1, $entity2));
272272

273-
$field = $this->factory->createNamed('entity', 'name', null, array(
273+
$field = $this->factory->createNamed('name', 'entity', null, array(
274274
'multiple' => false,
275275
'expanded' => false,
276276
'em' => 'default',
@@ -292,7 +292,7 @@ public function testSubmitSingleNonExpandedCompositeIdentifier()
292292

293293
$this->persist(array($entity1, $entity2));
294294

295-
$field = $this->factory->createNamed('entity', 'name', null, array(
295+
$field = $this->factory->createNamed('name', 'entity', null, array(
296296
'multiple' => false,
297297
'expanded' => false,
298298
'em' => 'default',
@@ -316,7 +316,7 @@ public function testSubmitMultipleNonExpandedSingleIdentifier()
316316

317317
$this->persist(array($entity1, $entity2, $entity3));
318318

319-
$field = $this->factory->createNamed('entity', 'name', null, array(
319+
$field = $this->factory->createNamed('name', 'entity', null, array(
320320
'multiple' => true,
321321
'expanded' => false,
322322
'em' => 'default',
@@ -341,7 +341,7 @@ public function testSubmitMultipleNonExpandedSingleIdentifier_existingData()
341341

342342
$this->persist(array($entity1, $entity2, $entity3));
343343

344-
$field = $this->factory->createNamed('entity', 'name', null, array(
344+
$field = $this->factory->createNamed('name', 'entity', null, array(
345345
'multiple' => true,
346346
'expanded' => false,
347347
'em' => 'default',
@@ -372,7 +372,7 @@ public function testSubmitMultipleNonExpandedCompositeIdentifier()
372372

373373
$this->persist(array($entity1, $entity2, $entity3));
374374

375-
$field = $this->factory->createNamed('entity', 'name', null, array(
375+
$field = $this->factory->createNamed('name', 'entity', null, array(
376376
'multiple' => true,
377377
'expanded' => false,
378378
'em' => 'default',
@@ -398,7 +398,7 @@ public function testSubmitMultipleNonExpandedCompositeIdentifier_existingData()
398398

399399
$this->persist(array($entity1, $entity2, $entity3));
400400

401-
$field = $this->factory->createNamed('entity', 'name', null, array(
401+
$field = $this->factory->createNamed('name', 'entity', null, array(
402402
'multiple' => true,
403403
'expanded' => false,
404404
'em' => 'default',
@@ -428,7 +428,7 @@ public function testSubmitSingleExpanded()
428428

429429
$this->persist(array($entity1, $entity2));
430430

431-
$field = $this->factory->createNamed('entity', 'name', null, array(
431+
$field = $this->factory->createNamed('name', 'entity', null, array(
432432
'multiple' => false,
433433
'expanded' => true,
434434
'em' => 'default',
@@ -454,7 +454,7 @@ public function testSubmitMultipleExpanded()
454454

455455
$this->persist(array($entity1, $entity2, $entity3));
456456

457-
$field = $this->factory->createNamed('entity', 'name', null, array(
457+
$field = $this->factory->createNamed('name', 'entity', null, array(
458458
'multiple' => true,
459459
'expanded' => true,
460460
'em' => 'default',
@@ -484,7 +484,7 @@ public function testOverrideChoices()
484484

485485
$this->persist(array($entity1, $entity2, $entity3));
486486

487-
$field = $this->factory->createNamed('entity', 'name', null, array(
487+
$field = $this->factory->createNamed('name', 'entity', null, array(
488488
'em' => 'default',
489489
'class' => self::SINGLE_IDENT_CLASS,
490490
// not all persisted entities should be displayed
@@ -509,7 +509,7 @@ public function testGroupByChoices()
509509

510510
$this->persist(array($item1, $item2, $item3, $item4));
511511

512-
$field = $this->factory->createNamed('entity', 'name', null, array(
512+
$field = $this->factory->createNamed('name', 'entity', null, array(
513513
'em' => 'default',
514514
'class' => self::ITEM_GROUP_CLASS,
515515
'choices' => array($item1, $item2, $item3, $item4),
@@ -535,7 +535,7 @@ public function testDisallowChoicesThatAreNotIncluded_choicesSingleIdentifier()
535535

536536
$this->persist(array($entity1, $entity2, $entity3));
537537

538-
$field = $this->factory->createNamed('entity', 'name', null, array(
538+
$field = $this->factory->createNamed('name', 'entity', null, array(
539539
'em' => 'default',
540540
'class' => self::SINGLE_IDENT_CLASS,
541541
'choices' => array($entity1, $entity2),
@@ -556,7 +556,7 @@ public function testDisallowChoicesThatAreNotIncluded_choicesCompositeIdentifier
556556

557557
$this->persist(array($entity1, $entity2, $entity3));
558558

559-
$field = $this->factory->createNamed('entity', 'name', null, array(
559+
$field = $this->factory->createNamed('name', 'entity', null, array(
560560
'em' => 'default',
561561
'class' => self::COMPOSITE_IDENT_CLASS,
562562
'choices' => array($entity1, $entity2),
@@ -579,7 +579,7 @@ public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleIdentifie
579579

580580
$repository = $this->em->getRepository(self::SINGLE_IDENT_CLASS);
581581

582-
$field = $this->factory->createNamed('entity', 'name', null, array(
582+
$field = $this->factory->createNamed('name', 'entity', null, array(
583583
'em' => 'default',
584584
'class' => self::SINGLE_IDENT_CLASS,
585585
'query_builder' => $repository->createQueryBuilder('e')
@@ -601,7 +601,7 @@ public function testDisallowChoicesThatAreNotIncludedQueryBuilderAsClosureSingle
601601

602602
$this->persist(array($entity1, $entity2, $entity3));
603603

604-
$field = $this->factory->createNamed('entity', 'name', null, array(
604+
$field = $this->factory->createNamed('name', 'entity', null, array(
605605
'em' => 'default',
606606
'class' => self::SINGLE_IDENT_CLASS,
607607
'query_builder' => function ($repository) {
@@ -625,7 +625,7 @@ public function testDisallowChoicesThatAreNotIncludedQueryBuilderAsClosureCompos
625625

626626
$this->persist(array($entity1, $entity2, $entity3));
627627

628-
$field = $this->factory->createNamed('entity', 'name', null, array(
628+
$field = $this->factory->createNamed('name', 'entity', null, array(
629629
'em' => 'default',
630630
'class' => self::COMPOSITE_IDENT_CLASS,
631631
'query_builder' => function ($repository) {
@@ -647,7 +647,7 @@ public function testSubmitSingleStringIdentifier()
647647

648648
$this->persist(array($entity1));
649649

650-
$field = $this->factory->createNamed('entity', 'name', null, array(
650+
$field = $this->factory->createNamed('name', 'entity', null, array(
651651
'multiple' => false,
652652
'expanded' => false,
653653
'em' => 'default',
@@ -668,7 +668,7 @@ public function testSubmitCompositeStringIdentifier()
668668

669669
$this->persist(array($entity1));
670670

671-
$field = $this->factory->createNamed('entity', 'name', null, array(
671+
$field = $this->factory->createNamed('name', 'entity', null, array(
672672
'multiple' => false,
673673
'expanded' => false,
674674
'em' => 'default',

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected function tearDown()
6969
public function testThemeBlockInheritanceUsingUse()
7070
{
7171
$view = $this->factory
72-
->createNamed('email', 'name')
72+
->createNamed('name', 'email')
7373
->createView()
7474
;
7575

@@ -84,7 +84,7 @@ public function testThemeBlockInheritanceUsingUse()
8484
public function testThemeBlockInheritanceUsingExtend()
8585
{
8686
$view = $this->factory
87-
->createNamed('email', 'name')
87+
->createNamed('name', 'email')
8888
->createView()
8989
;
9090

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,5 @@ CHANGELOG
131131
* FormEvents::PRE_BIND now replaces FormEvents::BIND_CLIENT_DATA
132132
* deprecated FormEvents::SET_DATA, FormEvents::BIND_CLIENT_DATA and
133133
FormEvents::BIND_NORM_DATA
134+
* [BC BREAK] reversed the order of the first two arguments to `createNamed`
135+
and `createNamedBuilder` in `FormFactoryInterface`

src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function preSetData(FormEvent $event)
9090

9191
// Then add all rows again in the correct order
9292
foreach ($data as $name => $value) {
93-
$form->add($this->factory->createNamed($this->type, $name, null, array_replace(array(
93+
$form->add($this->factory->createNamed($name, $this->type, null, array_replace(array(
9494
'property_path' => '['.$name.']',
9595
), $this->options)));
9696
}
@@ -122,7 +122,7 @@ public function preBind(FormEvent $event)
122122
if ($this->allowAdd) {
123123
foreach ($data as $name => $value) {
124124
if (!$form->has($name)) {
125-
$form->add($this->factory->createNamed($this->type, $name, null, array_replace(array(
125+
$form->add($this->factory->createNamed($name, $this->type, null, array_replace(array(
126126
'property_path' => '['.$name.']',
127127
), $this->options)));
128128
}

src/Symfony/Component/Form/Extension/Csrf/Type/FormTypeCsrfExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function finishView(FormViewInterface $view, FormInterface $form, array $
6565
$factory = $form->getConfig()->getAttribute('csrf_factory');
6666
$data = $options['csrf_provider']->generateCsrfToken($options['intention']);
6767

68-
$csrfForm = $factory->createNamed('hidden', $options['csrf_field_name'], $data, array(
68+
$csrfForm = $factory->createNamed($options['csrf_field_name'], 'hidden', $data, array(
6969
'property_path' => false,
7070
));
7171

src/Symfony/Component/Form/FormBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function create($name, $type = null, array $options = array())
121121
}
122122

123123
if (null !== $type) {
124-
return $this->getFormFactory()->createNamedBuilder($type, $name, null, $options, $this);
124+
return $this->getFormFactory()->createNamedBuilder($name, $type, null, $options, $this);
125125
}
126126

127127
return $this->getFormFactory()->createBuilderForProperty($this->getDataClass(), $name, null, $options, $this);

src/Symfony/Component/Form/FormFactory.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ public function create($type, $data = null, array $options = array(), FormBuilde
117117
/**
118118
* {@inheritdoc}
119119
*/
120-
public function createNamed($type, $name, $data = null, array $options = array(), FormBuilder $parent = null)
120+
public function createNamed($name, $type, $data = null, array $options = array(), FormBuilder $parent = null)
121121
{
122-
return $this->createNamedBuilder($type, $name, $data, $options, $parent)->getForm();
122+
return $this->createNamedBuilder($name, $type, $data, $options, $parent)->getForm();
123123
}
124124

125125
/**
@@ -137,21 +137,20 @@ public function createBuilder($type, $data = null, array $options = array(), For
137137
{
138138
$name = is_object($type) ? $type->getName() : $type;
139139

140-
return $this->createNamedBuilder($type, $name, $data, $options, $parent);
140+
return $this->createNamedBuilder($name, $type, $data, $options, $parent);
141141
}
142142

143143
/**
144144
* {@inheritdoc}
145145
*/
146-
public function createNamedBuilder($type, $name, $data = null, array $options = array(), FormBuilder $parent = null)
146+
public function createNamedBuilder($name, $type, $data = null, array $options = array(), FormBuilder $parent = null)
147147
{
148148
if (!array_key_exists('data', $options)) {
149149
$options['data'] = $data;
150150
}
151151

152152
$builder = null;
153153
$types = array();
154-
$knownOptions = array();
155154
$optionsResolver = new OptionsResolver();
156155

157156
// Bottom-up determination of the type hierarchy
@@ -281,7 +280,7 @@ public function createBuilderForProperty($class, $property, $data = null, array
281280
$options = array_merge($typeGuess->getOptions(), $options);
282281
}
283282

284-
return $this->createNamedBuilder($type, $property, $data, $options, $parent);
283+
return $this->createNamedBuilder($property, $type, $data, $options, $parent);
285284
}
286285

287286
/**

0 commit comments

Comments
 (0)
0