8000 [Form] fix "prototype" not required when parent form is not required by HeahDude · Pull Request #18317 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] fix "prototype" not required when parent form is not required #18317

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

Merged
merged 1 commit into from
Apr 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
8000
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Form] fix "prototype" not required when parent form is not required
  • Loading branch information
HeahDude committed Mar 31, 2016
commit 7df9ca2aebb1886d0d3ec54647aa110d019d5564
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public function buildView(FormView $view, FormInterface $form, array $options)
));

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,46 @@ public function testPrototypeSetNotRequired()
$this->assertFalse($form->createView()->vars['required'], 'collection is not required');
$this->assertFalse($form->createView()->vars['prototype']->vars['required'], '"prototype" should not be required');
}

public function testPrototypeSetNotRequiredIfParentNotRequired()
{
$child = $this->factory->create('collection', array(), array(
'type' => 'file',
'allow_add' => true,
'prototype' => true,
'prototype_name' => '__test__',
));

$parent = $this->factory->create('form', array(), array(
'required' => false,
));

$child->setParent($parent);
$this->assertFalse($parent->createView()->vars['required'], 'Parent is not required');
$this->assertFalse($child->createView()->vars['required'], 'Child is not required');
$this->assertFalse($child->createView()->vars['prototype']->vars['required'], '"Prototype" should not be required');
}

public function testPrototypeNotOverrideRequiredByEntryOptionsInFavorOfParent()
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the second test is redundant because required is true by default.

$child = $this->factory->create('collection', array(), array(
'type' => 'file',
'allow_add' => true,
'prototype' => true,
'prototype_name' => '__test__',
'options' => array(
'required' => true,
),
));

$parent = $this->factory->create('form', array(), array(
'required' => false,
));

$child->setParent($parent);

$this->assertFalse($parent->createView()->vars['required'], 'Parent is not required');
$this->assertFalse($child->createView()->vars['required'], 'Child is not required');
$this->assertFalse($child->createView()->vars['prototype']->vars['required'], '"Prototype" should not be required');
}
}
0