Skip to content

Commit

Permalink
[Form] fix "prototype" not required when parent form is not required
Browse files Browse the repository at this point in the history
  • Loading branch information
HeahDude committed Mar 31, 2016
1 parent 9945d8a commit 7df9ca2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
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
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()
{
$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 comments on commit 7df9ca2

Please sign in to comment.