8000 merged branch Tobion/formparent (PR #5357) · symfony/symfony@003f8c5 · GitHub
[go: up one dir, main page]

Skip to content
< 8000 script crossorigin="anonymous" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_github_remote-form_dist_index_js-node_modules_delegated-events_dist_inde-94fd67-e789af5a4655.js" defer="defer">

Commit 003f8c5

Browse files
committed
merged branch Tobion/formparent (PR #5357)
Commits ------- 30c1457 [Form] fixed Form::setParent(null) 214f0de [Form] added test with null parent Discussion ---------- [Form] fixed Form::setParent(null) --------------------------------------------------------------------------- by bschussek at 2012-08-29T10:58:20Z :+1:
2 parents af491b8 + 30c1457 commit 003f8c5

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/Symfony/Component/Form/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public function setParent(FormInterface $parent = null)
253253
throw new AlreadyBoundException('You cannot set the parent of a bound form');
254254
}
255255

256-
if ('' === $this->config->getName()) {
256+
if (null !== $parent && '' === $this->config->getName()) {
257257
throw new FormException('A form with an empty name cannot have a parent form.');
258258
}
259259

src/Symfony/Component/Form/FormInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
2121
/**
2222
* Sets the parent form.
2323
*
24-
* @param FormInterface $parent The parent form
24+
* @param FormInterface|null $parent The parent form or null if it's the root.
2525
*
2626
* @return FormInterface The form instance
2727
*
@@ -34,7 +34,7 @@ public function setParent(FormInterface $parent = null);
3434
/**
3535
* Returns the parent form.
3636
*
37-
* @return FormInterface The parent form
37+
* @return FormInterface|null The parent form or null if there is none.
3838
*/
3939
public function getParent();
4040

src/Symfony/Component/Form/Tests/SimpleFormTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,14 @@ public function testFormCanHaveEmptyName()
665665
$this->assertEquals('', $form->getName());
666666
}
667667

668+
public function testSetNullParentWorksWithEmptyName()
669+
{
670+
$form = $this->getBuilder('')->getForm();
671+
$form->setParent(null);
672+
673+
$this->assertNull($form->getParent());
674+
}
675+
668676
/**
669677
* @expectedException Symfony\Component\Form\Exception\FormException
670678
* @expectedExceptionMessage A form with an empty name cannot have a parent form.

0 commit comments

Comments
 (0)
0