Skip to content

Commit d73485a

Browse files
memphysfabpot
authored andcommitted
[Form] fix BC break introduced with prototype_data option
1 parent 3a57b77 commit d73485a

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ class CollectionType extends AbstractType
2727
public function buildForm(FormBuilderInterface $builder, array $options)
2828
{
2929
if ($options['allow_add'] && $options['prototype']) {
30-
$prototype = $builder->create($options['prototype_name'], $options['entry_type'], array_replace(array(
30+
$prototypeOptions = array_replace(array(
3131
'label' => $options['prototype_name'].'label__',
32-
), $options['entry_options'], array(
33-
'data' => $options['prototype_data'],
34-
)));
32+
), $options['options']);
33+
34+
if (null !== $options['prototype_data']) {
35+
$prototypeOptions['data'] = $options['prototype_data'];
36+
}
37+
38+
$prototype = $builder->create($options['prototype_name'], $options['entry_type'], $prototypeOptions);
3539
$builder->setAttribute('prototype', $prototype->getForm());
3640
}
3741

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,20 @@ public function testPrototypeData()
316316

317317
$this->assertSame('foo', $form->createView()->vars['prototype']->vars['value']);
318318
}
319+
320+
/**
321+
* @group legacy
322+
*/
323+
public function testLegacyPrototypeData()
324+
{
325+
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
326+
'allow_add' => true,
327+
'prototype' => true,
328+
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
329+
'options' => array(
330+
'data' => 'bar',
331+
),
332+
));
333+
$this->assertSame('bar', $form->createView()->vars['prototype']->vars['value']);
334+
}
319335
}

0 commit comments

Comments
 (0)