diff --git a/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php b/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php index 2fed7cea88a4c..817d67e2272bf 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php @@ -29,7 +29,9 @@ 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__', - ), $options['options'])); + ), $options['options'], array( + 'data' => $options['prototype_data'], + ))); $builder->setAttribute('prototype', $prototype->getForm()); } @@ -84,6 +86,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) 'allow_add' => false, 'allow_delete' => false, 'prototype' => true, + 'prototype_data' => null, 'prototype_name' => '__name__', '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 589ccdbb7ac21..ef00ea25bd84a 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php @@ -274,4 +274,19 @@ public function testPrototypeDefaultLabel() $this->assertSame('__test__label__', $form->createView()->vars['prototype']->vars['label']); } + + public function testPrototypeData() + { + $form = $this->factory->create('collection', array(), array( + 'type' => 'text', + 'allow_add' => true, + 'prototype' => true, + 'prototype_data' => 'foo', + 'options' => array( + 'data' => 'bar', + ), + )); + + $this->assertSame('foo', $form->createView()->vars['prototype']->vars['value']); + } }
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: