[Form] fix #15544 when a collection type attribute "required" is false, "prototype" should too

This commit is contained in:
Jules Pietri 2015-12-11 03:19:25 +01:00 committed by Fabien Potencier
parent 423f83f75e
commit b4b5d63660
2 changed files with 27 additions and 0 deletions

View File

@ -28,6 +28,7 @@ class CollectionType extends AbstractType
{
if ($options['allow_add'] && $options['prototype']) {
$prototype = $builder->create($options['prototype_name'], $options['type'], array_replace(array(
'required' => $options['required'],
'label' => $options['prototype_name'].'label__',
), $options['options']));
$builder->setAttribute('prototype', $prototype->getForm());

View File

@ -195,4 +195,30 @@ class CollectionTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
$this->assertSame('__test__label__', $form->createView()->vars['prototype']->vars['label']);
}
public function testPrototypeDefaultRequired()
{
$form = $this->factory->create('collection', array(), array(
'type' => 'file',
'allow_add' => true,
'prototype' => true,
'prototype_name' => '__test__',
));
$this->assertTrue($form->createView()->vars['prototype']->vars['required']);
}
public function testPrototypeSetNotRequired()
{
$form = $this->factory->create('collection', array(), array(
'type' => 'file',
'allow_add' => true,
'prototype' => true,
'prototype_name' => '__test__',
'required' => false,
));
$this->assertFalse($form->createView()->vars['required'], 'collection is not required');
$this->assertFalse($form->createView()->vars['prototype']->vars['required'], '"prototype" should not be required');
}
}