[Form] Add "prototype_data" option to collection type

This commit is contained in:
Kristen Gilden 2014-10-24 21:38:39 +03:00 committed by Bernhard Schussek
parent 09fabfeb1f
commit 80b0a80852
2 changed files with 19 additions and 1 deletions

View File

@ -29,7 +29,9 @@ class CollectionType extends AbstractType
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 @@ class CollectionType extends AbstractType
'allow_add' => false,
'allow_delete' => false,
'prototype' => true,
'prototype_data' => null,
'prototype_name' => '__name__',
'type' => 'text',
'options' => array(),

View File

@ -274,4 +274,19 @@ class CollectionTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
$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']);
}
}