Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 46e8805

Browse files
committed
bug #20080 [Form] compound forms without children should be considered
rendered
1 parent 80577f9 commit 46e8805

File tree

4 files changed

+63
-8
lines changed

4 files changed

+63
-8
lines changed

src/Symfony/Component/Form/FormView.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ public function __construct(FormView $parent = null)
6565
*/
6666
public function isRendered()
6767
{
68-
if (true === $this->rendered || 0 === count($this->children)) {
69-
return $this->rendered;
68+
if ($this->rendered) {
69+
return true;
70+
}
71+
72+
if (isset($this->vars['compound']) ? !$this->vars['compound'] : 0 === count($this->children)) {
73+
return false;
7074
}
7175

7276
foreach ($this->children as $child) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ public function testNestedFormError()
453453
$form = $this->factory->createNamedBuilder('name', 'form')
454454
->add($this->factory
455455
->createNamedBuilder('child', 'form', null, array('error_bubbling' => false))
456-
->add('grandChild', 'form')
456+
->add('grandChild', 'text')
457457
)
458458
->getForm();
459459

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public function testNestedFormError()
318318
$form = $this->factory->createNamedBuilder('name', 'form')
319319
->add($this->factory
320320
->createNamedBuilder('child', 'form', null, array('error_bubbling' => false))
321-
->add('grandChild', 'form')
321+
->add('grandChild', 'text')
322322
)
323323
->getForm();
324324

src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,16 +488,67 @@ public function testPassMultipartTrueIfAnyChildIsMultipartToView()
488488
$this->assertTrue($view->vars['multipart']);
489489
}
490490

491-
public function testViewIsNotRenderedByDefault()
491+
public function testViewIsConsideredRenderedForRenderedNonCompoundForms()
492+
{
493+
$view = $this->factory->createBuilder('form', null, array(
494+
'compound' => false,
495+
))
496+
->getForm()
497+
->createView();
498+
499+
$view->setRendered();
500+
501+
$this->assertTrue($view->isRendered());
502+
}
503+
504+
public function testViewIsNotConsideredRenderedImplicitlyForNonCompoundForms()
505+
{
506+
$view = $this->factory->createBuilder('form', null, array(
507+
'compound' => false,
508+
))
509+
->getForm()
510+
->createView();
511+
512+
$this->assertFalse($view->isRendered());
513+
}
514+
515+
public function testViewIsNotConsideredRenderedImplicitlyForCompoundFormsWithNonCompoundChildren()
492516
{
493517
$view = $this->factory->createBuilder('form')
494-
->add('foo', 'form')
495-
->getForm()
496-
->createView();
518+
->add('foo', 'form', array(
519+
'compound' => false,
520+
))
521+
->getForm()
522+
->createView();
497523

498524
$this->assertFalse($view->isRendered());
499525
}
500526

527+
public function testViewIsConsideredRenderedImplicitlyForCompoundFormsWithRenderedNonCompoundChildren()
528+
{
529+
$view = $this->factory->createBuilder('form')
530+
->add('foo', 'form', array(
531+
'compound' => false,
532+
))
533+
->getForm()
534+
->createView();
535+
536+
foreach ($view as $child) {
537+
$child->setRendered();
538+
}
539+
540+
$this->assertTrue($view->isRendered());
541+
}
542+
543+
public function testViewIsConsideredRenderedImplicitlyForCompoundFormsWithoutChildren()
544+
{
545+
$view = $this->factory->createBuilder('form')
546+
->getForm()
547+
->createView();
548+
549+
$this->assertTrue($view->isRendered());
550+
}
551+
501552
public function testErrorBubblingIfCompound()
502553
{
503554
$form = $this->factory->create('form', null, array(

0 commit comments

Comments
 (0)