Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 97ebca1

Browse files
committed
bug #18677 [DoctrineBridge] Fixed bc layer after #18069 (HeahDude)
This PR was merged into the 3.1-dev branch. Discussion ---------- [DoctrineBridge] Fixed bc layer after #18069 | Q | A | ------------- | --- | Branch? | master | Bug fix? | BC break | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | ~ | License | MIT | Doc PR | ~ Commits ------- 8a6cf9d [DoctrineBridge] fixed bc layer from #18069
2 parents b85ab60 + 8a6cf9d commit 97ebca1

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

src/Symfony/Bridge/Doctrine/Form/EventListener/MergeDoctrineCollectionListener.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,32 @@
2727
*/
2828
class MergeDoctrineCollectionListener implements EventSubscriberInterface
2929
{
30-
// Keeps BC. To be removed in 4.0
30+
// Keep BC. To be removed in 4.0
3131
private $bc = true;
32+
private $bcLayer = false;
3233

3334
public static function getSubscribedEvents()
3435
{
3536
// Higher priority than core MergeCollectionListener so that this one
3637
// is called before
3738
return array(
3839
FormEvents::SUBMIT => array(
39-
// BC
40-
array('onBind', 10),
40+
array('onBind', 10), // deprecated
4141
array('onSubmit', 5),
4242
),
4343
);
4444
}
4545

4646
public function onSubmit(FormEvent $event)
4747
{
48-
// If onBind() is overridden then logic has been executed
4948
if ($this->bc) {
49+
// onBind() has been overridden from a child class
5050
@trigger_error('The onBind() method is deprecated since version 3.1 and will be removed in 4.0. Use the onSubmit() method instead.', E_USER_DEPRECATED);
5151

52-
return;
52+
if (!$this->bcLayer) {
53+
// If parent::onBind() has not been called, then logic has been executed
54+
return;
55+
}
5356
}
5457

5558
$collection = $event->getForm()->getData();
@@ -68,10 +71,13 @@ public function onSubmit(FormEvent $event)
6871
* @deprecated since version 3.1, to be removed in 4.0.
6972
* Use {@link onSubmit()} instead.
7073
*/
71-
public function onBind()
74+
public function onBind(FormEvent $event)
7275
{
7376
if (__CLASS__ === get_class($this)) {
7477
$this->bc = false;
78+
} else {
79+
// parent::onBind() has been called
80+
$this->bcLayer = true;
7581
}
7682
}
7783
}

src/Symfony/Bridge/Doctrine/Tests/Form/EventListener/MergeDoctrineCollectionTest.php renamed to src/Symfony/Bridge/Doctrine/Tests/Form/EventListener/MergeDoctrineCollectionListenerTest.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Symfony\Component\Form\FormEvent;
1919
use Symfony\Component\Form\FormEvents;
2020

21-
class MergeDoctrineCollectionTest extends \PHPUnit_Framework_TestCase
21+
class MergeDoctrineCollectionListenerTest extends \PHPUnit_Framework_TestCase
2222
{
2323
/** @var \Doctrine\Common\Collections\ArrayCollection */
2424
private $collection;
@@ -77,4 +77,37 @@ public function testOnSubmitNullClearCollection()
7777

7878
$this->assertTrue($this->collection->isEmpty());
7979
}
80+
81+
/**
82+
* @group legacy
83+
*/
84+
public function testLegacyChildClassOnSubmitCallParent()
85+
{
86+
$form = $this->getBuilder('name')
87+
->setData($this->collection)
88+
->addEventSubscriber(new TestClassExtendingMergeDoctrineCollectionListener())
89+
->getForm();
90+
$submittedData = array();
91+
$event = new FormEvent($form, $submittedData);
92+
93+
$this->dispatcher->dispatch(FormEvents::SUBMIT, $event);
94+
95+
$this->assertTrue($this->collection->isEmpty());
96+
$this->assertTrue(TestClassExtendingMergeDoctrineCollectionListener::$onBindCalled);
97+
}
98+
}
99+
100+
/**
101+
* @group legacy
102+
*/
103+
class TestClassExtendingMergeDoctrineCollectionListener extends MergeDoctrineCollectionListener
104+
{
105+
public static $onBindCalled = false;
106+
107+
public function onBind(FormEvent $event)
108+
{
109+
self::$onBindCalled = true;
110+
111+
parent::onBind($event);
112+
}
80113
}

0 commit comments

Comments
 (0)