bug #13170 [Form] Set a child type to text if added to the form without a type. (jakzal)
This PR was merged into the 2.3 branch.
Discussion
----------
[Form] Set a child type to text if added to the form without a type.
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #13167
| License | MIT
| Doc PR | -
This copies the behaviour of `FormBuilder::create()` to `Form::add()`.
ping @webmozart
Commits
-------
57070a2
[Form] Set a child type to text if added to the form without a type.
This commit is contained in:
commit
d5e9de2f94
@ -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 {
|
||||
|
@ -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')
|
||||
|
Reference in New Issue
Block a user