From 3180abb7eceef5663be5640b218a4775c425e42d Mon Sep 17 00:00:00 2001 From: stoccc Date: Fri, 25 Aug 2017 09:11:28 +0200 Subject: [PATCH 1/4] fix for Form with an EntityType field with multiple=true giving back array and ArrayCollection fix for https://github.com/symfony/symfony/issues/23927, by yceruto https://github.com/symfony/symfony/issues/23927#issuecomment-324438146 --- .../Extension/Core/EventListener/MergeCollectionListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Extension/Core/EventListener/MergeCollectionListener.php b/src/Symfony/Component/Form/Extension/Core/EventListener/MergeCollectionListener.php index a65116fd5c8ce..0c16bd42ba9cd 100644 --- a/src/Symfony/Component/Form/Extension/Core/EventListener/MergeCollectionListener.php +++ b/src/Symfony/Component/Form/Extension/Core/EventListener/MergeCollectionListener.php @@ -80,7 +80,7 @@ public function onSubmit(FormEvent $event) return; } - if (!$dataToMergeInto) { + if (null === $dataToMergeInto) { // No original data was set. Set it if allowed if ($this->allowAdd) { $dataToMergeInto = $data; From 15f4a8eb8da46428bd3a08e18bb62718fee30ec0 Mon Sep 17 00:00:00 2001 From: stoccc Date: Fri, 25 Aug 2017 09:14:13 +0200 Subject: [PATCH 2/4] added tests Added tests for https://github.com/symfony/symfony/issues/23927 --- .../Tests/Form/Type/EntityTypeTest.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php index 587ebd6b3e24d..5365ed626c6ec 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php @@ -1482,4 +1482,38 @@ public function testSubmitNullExpandedMultiple() $this->assertEquals($collection, $form->getNormData()); $this->assertSame(array(), $form->getViewData(), 'View data is always an array'); } + + public function testSetDataEmptyArraySubmitNullMultiple() + { + $emptyArray = array(); + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'em' => 'default', + 'class' => self::SINGLE_IDENT_CLASS, + 'multiple' => true, + )); + $form->setData($emptyArray); + $form->submit(null); + $this->assertInternalType('array', $form->getData()); + $this->assertEquals(array(), $form->getData()); + $this->assertEquals(array(), $form->getNormData()); + $this->assertSame(array(), $form->getViewData(), 'View data is always an array'); + } + + public function testSetDataNonEmptyArraySubmitNullMultiple() + { + $entity1 = new SingleIntIdEntity(1, 'Foo'); + $this->persist(array($entity1)); + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'em' => 'default', + 'class' => self::SINGLE_IDENT_CLASS, + 'multiple' => true, + )); + $existing = array(0 => $entity1); + $form->setData($existing); + $form->submit(null); + $this->assertInternalType('array', $form->getData()); + $this->assertEquals(array(), $form->getData()); + $this->assertEquals(array(), $form->getNormData()); + $this->assertSame(array(), $form->getViewData(), 'View data is always an array'); + } } From 7e0d1d35c6168bc21cab279efaa42d83d58434fc Mon Sep 17 00:00:00 2001 From: stoccc Date: Fri, 25 Aug 2017 09:22:27 +0200 Subject: [PATCH 3/4] fix code style fix code style --- .../Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php index 5365ed626c6ec..a7d41ce8f3270 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php @@ -1482,7 +1482,7 @@ public function testSubmitNullExpandedMultiple() $this->assertEquals($collection, $form->getNormData()); $this->assertSame(array(), $form->getViewData(), 'View data is always an array'); } - + public function testSetDataEmptyArraySubmitNullMultiple() { $emptyArray = array(); @@ -1498,7 +1498,7 @@ public function testSetDataEmptyArraySubmitNullMultiple() $this->assertEquals(array(), $form->getNormData()); $this->assertSame(array(), $form->getViewData(), 'View data is always an array'); } - + public function testSetDataNonEmptyArraySubmitNullMultiple() { $entity1 = new SingleIntIdEntity(1, 'Foo'); From 380d26dc6630d806a3d8ce46a7232a4bea7f6d52 Mon Sep 17 00:00:00 2001 From: stoccc Date: Mon, 28 Aug 2017 22:06:56 +0200 Subject: [PATCH 4/4] Update composer.json --- src/Symfony/Bridge/Doctrine/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Doctrine/composer.json b/src/Symfony/Bridge/Doctrine/composer.json index 22635d45ecc7b..dc8e0d528f5db 100644 --- a/src/Symfony/Bridge/Doctrine/composer.json +++ b/src/Symfony/Bridge/Doctrine/composer.json @@ -22,7 +22,7 @@ "require-dev": { "symfony/stopwatch": "~2.2", "symfony/dependency-injection": "~2.2", - "symfony/form": "~2.7.25|^2.8.18", + "symfony/form": "~2.7.34|^2.8.27", "symfony/http-kernel": "~2.2", "symfony/property-access": "~2.3", "symfony/security": "~2.2",