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 7ee5392

Browse filesBrowse files
committed
[Form] fix "prototype" not required when parent form is not required
1 parent 09cc0b2 commit 7ee5392
Copy full SHA for 7ee5392

File tree

2 files changed

+43
-0
lines changed
Filter options

2 files changed

+43
-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
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public function buildView(FormView $view, FormInterface $form, array $options)
5656

5757
if ($form->getConfig()->hasAttribute('prototype')) {
5858
$view->vars['prototype'] = $form->getConfig()->getAttribute('prototype')->createView($view);
59+
60+
if ($view->parent && !$view->parent->vars['required']) {
61+
$view->vars['prototype']->vars['required'] = false;
62+
}
5963
}
6064
}
6165

‎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
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,43 @@ public function testPrototypeSetNotRequired()
221221
$this->assertFalse($form->createView()->vars['required'], 'collection is not required');
222222
$this->assertFalse($form->createView()->vars['prototype']->vars['required'], '"prototype" should not be required');
223223
}
224+
225+
public function testPrototypeSetNotRequiredIfParentNotRequired()
226+
{
227+
$child = $this->factory->create('collection', array(), array(
228+
'type' => 'file',
229+
'allow_add' => true,
230+
'prototype' => true,
231+
'prototype_name' => '__test__',
232+
));
233+
234+
$parent = $this->factory->create('form', array(), array(
235+
'required' => false,
236+
));
237+
238+
$child->setParent($parent);
239+
$this->assertFalse($parent->createView()->vars['required'], 'Parent is not required');
240+
$this->assertFalse($child->createView()->vars['required'], 'Child is not required');
241+
$this->assertFalse($child->createView()->vars['prototype']->vars['required'], '"Prototype" should not be required');
242+
}
243+
244+
public function testPrototypeSetNotRequiredIfParentNotRequiredAndChildRequired()
245+
{
246+
$child = $this->factory->create('collection', array(), array(
247+
'type' => 'file',
248+
'allow_add' => true,
249+
'prototype' => true,
250+
'prototype_name' => '__test__',
251+
'required' => true
252+
));
253+
254+
$parent = $this->factory->create('form', array(), array(
255+
'required' => false,
256+
));
257+
258+
$child->setParent($parent);
259+
$this->assertFalse($parent->createView()->vars['required'], 'Parent is not required');
260+
$this->assertFalse($child->createView()->vars['required'], 'Child is not required');
261+
$this->assertFalse($child->createView()->vars['prototype']->vars['required'], '"Prototype" should not be required');
262+
}
224263
}

0 commit comments

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