Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a85c9d1

Browse files
committed
[#5095] Add "prototype_data" option to collection type
1 parent 23f0411 commit a85c9d1

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ public function buildView(FormView $view, FormInterface $form, array $options)
5555
));
5656

5757
if ($form->getConfig()->hasAttribute('prototype')) {
58-
$view->vars['prototype'] = $form->getConfig()->getAttribute('prototype')->createView($view);
58+
$view->vars['prototype'] = $form
59+
->getConfig()
60+
->getAttribute('prototype')
61+
->setData($options['prototype_data'])
62+
->createView($view)
63+
;
5964
}
6065
}
6166

@@ -84,6 +89,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
8489
'allow_add' => false,
8590
'allow_delete' => false,
8691
'prototype' => true,
92+
'prototype_data' => null,
8793
'prototype_name' => '__name__',
8894
'type' => 'text',
8995
'options' => array(),

src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,16 @@ public function testPrototypeDefaultLabel()
274274

275275
$this->assertSame('__test__label__', $form->createView()->vars['prototype']->vars['label']);
276276
}
277+
278+
public function testPrototypeData()
279+
{
280+
$form = $this->factory->create('collection', array(), array(
281+
'type' => 'text',
282+
'allow_add' => true,
283+
'prototype' => true,
284+
'prototype_data' => 'foo',
285+
));
286+
287+
$this->assertSame('foo', $form->createView()->vars['prototype']->vars['value']);
288+
}
277289
}

0 commit comments

Comments
 (0)