Skip to content

Commit c081789

Browse files
committed
[Form] Deprecate FormEvent::setData() for events that do not allow it
1 parent 68f27ef commit c081789

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

UPGRADE-6.4.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Form
2929

3030
* Deprecate using `DateTime` or `DateTimeImmutable` model data with a different timezone than configured with the
3131
`model_timezone` option in `DateType`, `DateTimeType`, and `TimeType`
32+
* Deprecate `PostSetDataEvent::setData()` and `PostSubmitEvent::setData()`, these methods will throw an exception starting with 7.0
3233

3334
FrameworkBundle
3435
---------------

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Deprecate using `DateTime` or `DateTimeImmutable` model data with a different timezone than configured with the
88
`model_timezone` option in `DateType`, `DateTimeType`, and `TimeType`
9+
* Deprecate `PostSetDataEvent::setData()` and `PostSubmitEvent::setData()`, these methods will throw an exception starting with 7.0
910

1011
6.3
1112
---

src/Symfony/Component/Form/Event/PostSetDataEvent.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Form\Event;
1313

14+
use Symfony\Component\Form\Exception\BadMethodCallException;
1415
use Symfony\Component\Form\FormEvent;
1516

1617
/**
@@ -20,4 +21,11 @@
2021
*/
2122
final class PostSetDataEvent extends FormEvent
2223
{
24+
/**
25+
* @deprecated since Symfony 6.4, it will throw an exception in 7.0.
26+
*/
27+
public function setData(mixed $data)
28+
{
29+
// throw new BadMethodCallException('Form data cannot be changed during "form.post_set_data", you should use "form.pre_set_data" instead.');
30+
}
2331
}

src/Symfony/Component/Form/Event/PostSubmitEvent.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,11 @@
2121
*/
2222
final class PostSubmitEvent extends FormEvent
2323
{
24+
/**
25+
* @deprecated since Symfony 6.4, it will throw an exception in 7.0.
26+
*/
27+
public function setData(mixed $data)
28+
{
29+
// throw new BadMethodCallException('Form data cannot be changed during "form.post_submit", you should use "form.pre_submit" or "form.submit" instead.');
30+
}
2431
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy