Skip to content

Commit

Permalink
[Form] Add "prototype_data" option to collection type
Browse files Browse the repository at this point in the history
  • Loading branch information
kgilden authored and webmozart committed Jun 17, 2015
1 parent 09fabfe commit 80b0a80
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Expand Up @@ -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());
}

Expand Down Expand Up @@ -84,6 +86,7 @@ public function configureOptions(OptionsResolver $resolver)
'allow_add' => false,
'allow_delete' => false,
'prototype' => true,
'prototype_data' => null,
'prototype_name' => '__name__',
'type' => 'text',
'options' => array(),
Expand Down
Expand Up @@ -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']);
}
}

0 comments on commit 80b0a80

Please sign in to comment.