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
This commit is contained in:
commit
4c7c5ff489
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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']);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user