Skip to content

Commit f87ebd8

Browse 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 7011d88 + 8d29de5 commit f87ebd8

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Extension/Core/Type/CollectionType.php

Lines 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());

Tests/Extension/Core/Type/CollectionTypeTest.php

Lines 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)