Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5683718

Browse filesBrowse files
committed
[DoctrineBridge] fixed bc layer from #18069
1 parent 6857c36 commit 5683718
Copy full SHA for 5683718

File tree

2 files changed

+48
-7
lines changed
Filter options

2 files changed

+48
-7
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Form/EventListener/MergeDoctrineCollectionListener.php
+14-6Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,34 @@
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+
}
56+
// Reset the layer for next call
57+
$this->bcLayer = false;
5358
}
5459

5560
$collection = $event->getForm()->getData();
@@ -68,10 +73,13 @@ public function onSubmit(FormEvent $event)
6873
* @deprecated since version 3.1, to be removed in 4.0.
6974
* Use {@link onSubmit()} instead.
7075
*/
71-
public function onBind()
76+
public function onBind(FormEvent $event)
7277
{
7378
if (__CLASS__ === get_class($this)) {
7479
$this->bc = false;
80+
} else {
81+
// parent::onBind() has been called
82+
$this->bcLayer = true;
7583
}
7684
}
7785
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/Form/EventListener/MergeDoctrineCollectionListenerTest.php
+34-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.