Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 54bd6f7

Browse filesBrowse files
committed
feature #12314 [Form] Add "prototype_data" option to collection type (kgilden)
This PR was submitted for the master branch but it was merged into the 2.8 branch instead (closes #12314). Discussion ---------- [Form] Add "prototype_data" option to collection type | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #5095 | License | MIT | Doc PR | symfony/symfony-docs#4367 Makes it possible to have default data for collection prototypes. Commits ------- 80b0a80 [Form] Add "prototype_data" option to collection type
2 parents 09fabfe + 80b0a80 commit 54bd6f7
Copy full SHA for 54bd6f7

File tree

2 files changed

+19
-1
lines changed
Filter options

2 files changed

+19
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php
+4-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php
+15Lines 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+
'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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.