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 baa5b7d

Browse filesBrowse files
committed
bug #16959 [Form] fix #15544 when a collection type attribute "required" is false, "prototype" should too (HeahDude)
This PR was squashed before being merged into the 2.3 branch (closes #16959). Discussion ---------- [Form] fix #15544 when a collection type attribute "required" is false, "prototype" should too | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #15544 | License | MIT | Doc PR | - Commits ------- b4b5d63 [Form] fix #15544 when a collection type attribute "required" is false, "prototype" should too
2 parents 8d01023 + b4b5d63 commit baa5b7d
Copy full SHA for baa5b7d

File tree

2 files changed

+27
-0
lines changed
Filter options

2 files changed

+27
-0
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
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
2828
{
2929
if ($options['allow_add'] && $options['prototype']) {
3030
$prototype = $builder->create($options['prototype_name'], $options['type'], array_replace(array(
31+
'required' => $options['required'],
3132
'label' => $options['prototype_name'].'label__',
3233
), $options['options']));
3334
$builder->setAttribute('prototype', $prototype->getForm());

‎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
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,30 @@ public function testPrototypeDefaultLabel()
195195

196196
$this->assertSame('__test__label__', $form->createView()->vars['prototype']->vars['label']);
197197
}
198+
199+
public function testPrototypeDefaultRequired()
200+
{
201+
$form = $this->factory->create('collection', array(), array(
202+
'type' => 'file',
203+
'allow_add' => true,
204+
'prototype' => true,
205+
'prototype_name' => '__test__',
206+
));
207+
208+
$this->assertTrue($form->createView()->vars['prototype']->vars['required']);
209+
}
210+
211+
public function testPrototypeSetNotRequired()
212+
{
213+
$form = $this->factory->create('collection', array(), array(
214+
'type' => 'file',
215+
'allow_add' => true,
216+
'prototype' => true,
217+
'prototype_name' => '__test__',
218+
'required' => false,
219+
));
220+
221+
$this->assertFalse($form->createView()->vars['required'], 'collection is not required');
222+
$this->assertFalse($form->createView()->vars['prototype']->vars['required'], '"prototype" should not be required');
223+
}
198224
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.