[Form] Fix "Array was modified outside object" in ResizeFormListener.
This commit is contained in:
parent
d4a78fec32
commit
aa63faea06
@ -139,11 +139,17 @@ class ResizeFormListener implements EventSubscriberInterface
|
||||
// The data mapper only adds, but does not remove items, so do this
|
||||
// here
|
||||
if ($this->allowDelete) {
|
||||
$toDelete = array();
|
||||
|
||||
foreach ($data as $name => $child) {
|
||||
if (!$form->has($name)) {
|
||||
unset($data[$name]);
|
||||
$toDelete[] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($toDelete as $name) {
|
||||
unset($data[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
$event->setData($data);
|
||||
|
@ -254,7 +254,20 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array(), $event->getData());
|
||||
}
|
||||
|
||||
public function testOnSubmitDealsWithIteratorAggregate()
|
||||
public function testOnSubmitDealsWithObjectBackedIteratorAggregate()
|
||||
{
|
||||
$this->form->add($this->getForm('1'));
|
||||
|
||||
$data = new \ArrayObject(array(0 => 'first', 1 => 'second', 2 => 'third'));
|
||||
$event = new FormEvent($this->form, $data);
|
||||
$listener = new ResizeFormListener('text', array(), false, true);
|
||||
$listener->onSubmit($event);
|
||||
|
||||
$this->assertArrayNotHasKey(0, $event->getData());
|
||||
$this->assertArrayNotHasKey(2, $event->getData());
|
||||
}
|
||||
|
||||
public function testOnSubmitDealsWithArrayBackedIteratorAggregate()
|
||||
{
|
||||
$this->form->add($this->getForm('1'));
|
||||
|
||||
|
Reference in New Issue
Block a user