[Form] fix BC break introduced with prototype_data option

This commit is contained in:
Roma Lapin 2015-12-17 09:30:01 +03:00 committed by Fabien Potencier
parent 3a57b77bc7
commit d73485a821
2 changed files with 24 additions and 4 deletions

View File

@ -27,11 +27,15 @@ class CollectionType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
if ($options['allow_add'] && $options['prototype']) {
$prototype = $builder->create($options['prototype_name'], $options['entry_type'], array_replace(array(
$prototypeOptions = array_replace(array(
'label' => $options['prototype_name'].'label__',
), $options['entry_options'], array(
'data' => $options['prototype_data'],
)));
), $options['options']);
if (null !== $options['prototype_data']) {
$prototypeOptions['data'] = $options['prototype_data'];
}
$prototype = $builder->create($options['prototype_name'], $options['entry_type'], $prototypeOptions);
$builder->setAttribute('prototype', $prototype->getForm());
}

View File

@ -316,4 +316,20 @@ class CollectionTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
$this->assertSame('foo', $form->createView()->vars['prototype']->vars['value']);
}
/**
* @group legacy
*/
public function testLegacyPrototypeData()
{
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), array(
'allow_add' => true,
'prototype' => true,
'type' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
'options' => array(
'data' => 'bar',
),
));
$this->assertSame('bar', $form->createView()->vars['prototype']->vars['value']);
}
}