diff --git a/src/Symfony/Component/Form/FormView.php b/src/Symfony/Component/Form/FormView.php index 401288cf83d91..73e38d358eef8 100644 --- a/src/Symfony/Component/Form/FormView.php +++ b/src/Symfony/Component/Form/FormView.php @@ -65,8 +65,12 @@ public function __construct(FormView $parent = null) */ public function isRendered() { - if (true === $this->rendered || 0 === count($this->children)) { - return $this->rendered; + if ($this->rendered) { + return true; + } + + if (isset($this->vars['compound']) ? !$this->vars['compound'] : 0 === count($this->children)) { + return false; } foreach ($this->children as $child) { diff --git a/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php index 511c7f138cc7f..2c152ea49e65f 100644 --- a/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php @@ -453,7 +453,7 @@ public function testNestedFormError() $form = $this->factory->createNamedBuilder('name', 'form') ->add($this->factory ->createNamedBuilder('child', 'form', null, array('error_bubbling' => false)) - ->add('grandChild', 'form') + ->add('grandChild', 'text') ) ->getForm(); diff --git a/src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php index f655d17cd65a0..dada6f03a0445 100644 --- a/src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php @@ -318,7 +318,7 @@ public function testNestedFormError() $form = $this->factory->createNamedBuilder('name', 'form') ->add($this->factory ->createNamedBuilder('child', 'form', null, array('error_bubbling' => false)) - ->add('grandChild', 'form') + ->add('grandChild', 'text') ) ->getForm(); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php index 2b4b255b0daab..d7c5cb40501ce 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php @@ -488,16 +488,67 @@ public function testPassMultipartTrueIfAnyChildIsMultipartToView() $this->assertTrue($view->vars['multipart']); } - public function testViewIsNotRenderedByDefault() + public function testViewIsConsideredRenderedForRenderedNonCompoundForms() + { + $view = $this->factory->createBuilder('form', null, array( + 'compound' => false, + )) + ->getForm() + ->createView(); + + $view->setRendered(); + + $this->assertTrue($view->isRendered()); + } + + public function testViewIsNotConsideredRenderedImplicitlyForNonCompoundForms() + { + $view = $this->factory->createBuilder('form', null, array( + 'compound' => false, + )) + ->getForm() + ->createView(); + + $this->assertFalse($view->isRendered()); + } + + public function testViewIsNotConsideredRenderedImplicitlyForCompoundFormsWithNonCompoundChildren() { $view = $this->factory->createBuilder('form') - ->add('foo', 'form') - ->getForm() - ->createView(); + ->add('foo', 'form', array( + 'compound' => false, + )) + ->getForm() + ->createView(); $this->assertFalse($view->isRendered()); } + public function testViewIsConsideredRenderedImplicitlyForCompoundFormsWithRenderedNonCompoundChildren() + { + $view = $this->factory->createBuilder('form') + ->add('foo', 'form', array( + 'compound' => false, + )) + ->getForm() + ->createView(); + + foreach ($view as $child) { + $child->setRendered(); + } + + $this->assertTrue($view->isRendered()); + } + + public function testViewIsConsideredRenderedImplicitlyForCompoundFormsWithoutChildren() + { + $view = $this->factory->createBuilder('form') + ->getForm() + ->createView(); + + $this->assertTrue($view->isRendered()); + } + public function testErrorBubblingIfCompound() { $form = $this->factory->create('form', null, array(