Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4c7c5ff

Browse files
committed
bug #17044 [Form] fix BC break introduced with prototype_data option (memphys)
This PR was squashed before being merged into the 2.8 branch (closes #17044). Discussion ---------- [Form] fix BC break introduced with prototype_data option | Q | A | ------------- | --- | Bug fix? | [yes] | New feature? | [no] | BC breaks? | [no] | Deprecations? | [no] | Tests pass? | [no] | Fixed tickets | [#15707] | License | MIT | Doc PR | [] This fixes the BC break introduced with prototype_data option in collection type. At the moment whether option is set or not it overwrites prototype data but it has different behaviour before and prototype data was taken from the mapped form data/entity. - [x] make the test work (can't figure yet how to test that prototype without prototype_data option has default values) Commits ------- d73485a [Form] fix BC break introduced with prototype_data option
2 parents eae9e1c + d73485a commit 4c7c5ff

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)