8000 [Form] Add "prototype_data" option to collection type by kgilden · Pull Request #12314 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Add "prototype_data" option to collection type #12314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[#5095] Make sure "prototype_data" overrides "data" option
The "data" option under the "options" option intended for the target
form type would previously overwrite "prototype_data".
  • Loading branch information
kgilden committed Jan 31, 2015
commit f520c3c8fce881b5d5a7c71a80fd8268cd10df3b
Original file line number Diff line number Diff line change
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 All @@ -55,12 +57,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
));

if ($form->getConfig()->hasAttribute('prototype')) {
$view->vars['prototype'] = $form
->getConfig()
->getAttribute('prototype')
->setData($options['prototype_data'])
->createView($view)
;
$view->vars['prototype'] = $form->getConfig()->getAttribute('prototype')->createView($view);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ public function testPrototypeData()
'allow_add' => true,
'prototype' => true,
'prototype_data' => 'foo',
'options' => array(
'data' => 'bar',
),
));

$this->assertSame('foo', $form->createView()->vars['prototype']->vars['value']);
Expand Down
0