Skip to content

Commit 4120f13

Browse files
committed
[Form] Added all() method to the FormBuilder class
In order to perform some introspection on a FormBuilder instance, we need to be able to get its children. Almost everything is accessible in this class, but the children are not. This PR adds a all() method to respect the current API (get(), remove(), ...).
1 parent 05842c5 commit 4120f13

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/Symfony/Component/Form/FormBuilder.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,16 @@ public function has($name)
643643
return isset($this->children[$name]);
644644
}
645645

646+
/**
647+
* Returns the children.
648+
*
649+
* @return array
650+
*/
651+
public function all()
652+
{
653+
return $this->children;
654+
}
655+
646656
/**
647657
* Creates the form.
648658
*

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,22 @@ public function testAdd()
110110
$this->assertTrue($this->builder->has('foo'));
111111
}
112112

113+
public function testAll()
114+
{
115+
$this->assertEquals(0, count($this->builder->all()));
116+
$this->assertFalse($this->builder->has('foo'));
117+
118+
$this->builder->add('foo', 'text');
119+
$children = $this->builder->all();
120+
121+
$this->assertTrue($this->builder->has('foo'));
122+
$this->assertEquals(1, count($children));
123+
$this->assertArrayHasKey('foo', $children);
124+
125+
$foo = $children['foo'];
126+
$this->assertEquals('text', $foo['type']);
127+
}
128+
113129
public function testAddFormType()
114130
{
115131
$this->assertFalse($this->builder->has('foo'));

0 commit comments

Comments
 (0)