You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bug #22140 [Form] Improve the exceptions when trying to get the data in a PRE_SET_DATA listener and the data has not already been set (fancyweb)
This PR was merged into the 2.7 branch.
Discussion
----------
[Form] Improve the exceptions when trying to get the data in a PRE_SET_DATA listener and the data has not already been set
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #22103
| License | MIT
| Doc PR | -
Commits
-------
ef39b70 [Form] Improve the exceptions when trying to get the data in a PRE_SET_DATA listener and the data has not already been set
Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Form.php
+12Lines changed: 12 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -408,6 +408,10 @@ public function getData()
408
408
}
409
409
410
410
if (!$this->defaultDataSet) {
411
+
if ($this->lockSetData) {
412
+
thrownewRuntimeException('A cycle was detected. Listeners to the PRE_SET_DATA event must not call getData() if the form data has not already been set. You should call getData() on the FormEvent object instead.');
413
+
}
414
+
411
415
$this->setData($this->config->getData());
412
416
}
413
417
@@ -428,6 +432,10 @@ public function getNormData()
428
432
}
429
433
430
434
if (!$this->defaultDataSet) {
435
+
if ($this->lockSetData) {
436
+
thrownewRuntimeException('A cycle was detected. Listeners to the PRE_SET_DATA event must not call getNormData() if the form data has not already been set.');
437
+
}
438
+
431
439
$this->setData($this->config->getData());
432
440
}
433
441
@@ -448,6 +456,10 @@ public function getViewData()
448
456
}
449
457
450
458
if (!$this->defaultDataSet) {
459
+
if ($this->lockSetData) {
460
+
thrownewRuntimeException('A cycle was detected. Listeners to the PRE_SET_DATA event must not call getViewData() if the form data has not already been set.');
* @expectedExceptionMessage A cycle was detected. Listeners to the PRE_SET_DATA event must not call setData(). You should call setData() on the FormEvent object instead.
906
907
*/
907
908
publicfunctiontestSetDataCannotInvokeItself()
908
909
{
@@ -1084,6 +1085,51 @@ public function testCustomOptionsResolver()
* @expectedExceptionMessage A cycle was detected. Listeners to the PRE_SET_DATA event must not call getData() if the form data has not already been set. You should call getData() on the FormEvent object instead.
* @expectedExceptionMessage A cycle was detected. Listeners to the PRE_SET_DATA event must not call getNormData() if the form data has not already been set.
* @expectedExceptionMessage A cycle was detected. Listeners to the PRE_SET_DATA event must not call getViewData() if the form data has not already been set.
0 commit comments