[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().
This commit is contained in:
Jakub Zalas 2014-12-30 11:40:10 +00:00
parent 844741a192
commit 57070a2247
2 changed files with 20 additions and 0 deletions

View File

@ -873,6 +873,10 @@ class Form implements \IteratorAggregate, FormInterface
// Never initialize child forms automatically
$options['auto_initialize'] = false;
if (null === $type && null === $this->config->getDataClass()) {
$type = 'text';
}
if (null === $type) {
$child = $this->config->getFormFactory()->createForProperty($this->config->getDataClass(), $child, null, $options);
} else {

View File

@ -207,6 +207,22 @@ class CompoundFormTest extends AbstractFormTest
$this->assertSame(array(0 => $child), $this->form->all());
}
public function testAddWithoutType()
{
$child = $this->getBuilder('foo')->getForm();
$this->factory->expects($this->once())
->method('createNamed')
->with('foo', 'text')
->will($this->returnValue($child));
$this->form->add('foo');
$this->assertTrue($this->form->has('foo'));
$this->assertSame($this->form, $child->getParent());
$this->assertSame(array('foo' => $child), $this->form->all());
}
public function testAddUsingNameButNoType()
{
$this->form = $this->getBuilder('name', null, '\stdClass')