8000 [Form] Add "prototype_data" option to collection type · wouterj/symfony@80b0a80 · GitHub
[go: up one dir, main page]

Skip to content

Commit 80b0a80

Browse files
kgildenwebmozart
authored andcommitted
[Form] Add "prototype_data" option to collection type
1 parent 09fabfe commit 80b0a80

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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public function buildForm(FormBuilderInterface $builder, array $options)
2929
if ($options['allow_add'] && $options['prototype']) {
3030
$prototype = $builder->create($options['prototype_name'], $options['type'], array_replace(array(
3131
'label' => $options['prototype_name'].'label__',
32-
), $options['options']));
32+
), $options['options'], array(
33+
'data' => $options['prototype_data'],
34+
)));
3335
$builder->setAttribute('prototype', $prototype->getForm());
3436
}
3537

@@ -84,6 +86,7 @@ public function configureOptions(OptionsResolver $resolver)
8486
'allow_add' => false,
8587
'allow_delete' => false,
8688
'prototype' => true,
89+
'prototype_data' => null,
8790
'prototype_name' => '__name__',
8891
'type' => 'text',
8992
'options' => array(),

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,19 @@ 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+
' 66FA ;prototype' => true,
284+
'prototype_data' => 'foo',
285+
'options' => array(
286+
'data' => 'bar',
287+
),
288+
));
289+
290+
$this->assertSame('foo', $form->createView()->vars['prototype']->vars['value']);
291+
}
277292
}

0 commit comments

Comments
 (0)
0