Skip to content

Commit 79af0f3

Browse files
committed
[Form] Set a child type to text if added to the form without a type.
This copies the behaviour of the FormBuilder::create() to the Form::add().
1 parent 0d3a272 commit 79af0f3

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Form.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,10 @@ public function add($child, $type = null, array $options = array())
873873
// Never initialize child forms automatically
874874
$options['auto_initialize'] = false;
875875

876+
if (null === $type && null === $this->config->getDataClass()) {
877+
$type = 'text';
878+
}
879+
876880
if (null === $type) {
877881
$child = $this->config->getFormFactory()->createForProperty($this->config->getDataClass(), $child, null, $options);
878882
} else {

Tests/CompoundFormTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,22 @@ public function testAddUsingIntegerNameAndType()
207207
$this->assertSame(array(0 => $child), $this->form->all());
208208
}
209209

210+
public function testAddWithoutType()
211+
{
212+
$child = $this->getBuilder('foo')->getForm();
213+
214+
$this->factory->expects($this->once())
215+
->method('createNamed')
216+
->with('foo', 'text')
217+
->will($this->returnValue($child));
218+
219+
$this->form->add('foo');
220+
221+
$this->assertTrue($this->form->has('foo'));
222+
$this->assertSame($this->form, $child->getParent());
223+
$this->assertSame(array('foo' => $child), $this->form->all());
224+
}
225+
210226
public function testAddUsingNameButNoType()
211227
{
212228
$this->form = $this->getBuilder('name', null, '\stdClass')

0 commit comments

Comments
 (0)