[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:
parent
844741a192
commit
57070a2247
@ -873,6 +873,10 @@ class Form implements \IteratorAggregate, FormInterface
|
|||||||
// Never initialize child forms automatically
|
// Never initialize child forms automatically
|
||||||
$options['auto_initialize'] = false;
|
$options['auto_initialize'] = false;
|
||||||
|
|
||||||
|
if (null === $type && null === $this->config->getDataClass()) {
|
||||||
|
$type = 'text';
|
||||||
|
}
|
||||||
|
|
||||||
if (null === $type) {
|
if (null === $type) {
|
||||||
$child = $this->config->getFormFactory()->createForProperty($this->config->getDataClass(), $child, null, $options);
|
$child = $this->config->getFormFactory()->createForProperty($this->config->getDataClass(), $child, null, $options);
|
||||||
} else {
|
} else {
|
||||||
|
@ -207,6 +207,22 @@ class CompoundFormTest extends AbstractFormTest
|
|||||||
$this->assertSame(array(0 => $child), $this->form->all());
|
$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()
|
public function testAddUsingNameButNoType()
|
||||||
{
|
{
|
||||||
$this->form = $this->getBuilder('name', null, '\stdClass')
|
$this->form = $this->getBuilder('name', null, '\stdClass')
|
||||||
|
Reference in New Issue
Block a user