diff --git a/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php b/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php index 3ff36b97277d5..644b6433d4bd1 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php @@ -29,6 +29,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) if ($options['allow_add'] && $options['prototype']) { $prototype = $builder->create($options['prototype_name'], $options['type'], array_replace(array( 'label' => $options['prototype_name'] . 'label__', + 'data' => $options['prototype_data'], ), $options['options'])); $builder->setAttribute('prototype', $prototype->getForm()); } @@ -84,6 +85,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) 'allow_delete' => false, 'prototype' => true, 'prototype_name' => '__name__', + 'prototype_data' => null, 'type' => 'text', 'options' => array(), )); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php index 15896dae22f37..c223e3d124d97 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php @@ -197,4 +197,16 @@ public function testPrototypeDefaultLabel() $this->assertSame('__test__label__', $form->createView()->vars['prototype']->vars['label']); } + + public function testPrototypeData() + { + $form = $this->factory->create('collection', array(), array( + 'type' => 'form', + 'allow_add' => true, + 'prototype' => true, + 'prototype_data' => $data = 'foobar', + )); + + $this->assertEquals($data, $form->getConfig()->getAttribute('prototype')->getData()); + } }
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: