8000 feature #51043 [Form] Deprecate `FormEvent::setData()` for events tha… · symfony/symfony@503a7b3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 503a7b3

Browse files
feature #51043 [Form] Deprecate FormEvent::setData() for events that do not allow it (HeahDude)
This PR was merged into the 6.4 branch. Discussion ---------- [Form] Deprecate `FormEvent::setData()` for events that do not allow it | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | ~ | License | MIT | Doc PR | TODO Now that specific classes exist for each event, we can improve DX by forbidding to call `FormEvent::setData()` where it does not make sense. Commits ------- 0d318d0 [Form] Deprecate `FormEvent::setData()` for events that do not allow it
2 parents bd04cda + 0d318d0 commit 503a7b3

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

UPGRADE-6.4.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ 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()`, use `PreSetDataEvent::setData()` instead
33+
* Deprecate `PostSubmitEvent::setData()`, use `PreSubmitDataEvent::setData()` or `SubmitDataEvent::setData()` instead
3234

3335
FrameworkBundle
3436
---------------

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ 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()`, use `PreSetDataEvent::setData()` instead
10+
* Deprecate `PostSubmitEvent::setData()`, use `PreSubmitDataEvent::setData()` or `SubmitDataEvent::setData()` instead
911

1012
6.3
1113
---

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

Lines changed: 9 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,12 @@
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): void
28+
{
29+
trigger_deprecation('symfony/form', '6.4', 'Calling "%s()" will throw an exception as of 7.0, listen to "form.pre_set_data" instead.', __METHOD__);
30+
// throw new BadMethodCallException('Form data cannot be changed during "form.post_set_data", you should use "form.pre_set_data" instead.');
31+
}
2332
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,12 @@
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): void
28+
{
29+
trigger_deprecation('symfony/form', '6.4', 'Calling "%s()" will throw an exception as of 7.0, listen to "form.pre_submit" or "form.submit" instead.', __METHOD__);
30+
// throw new BadMethodCallException('Form data cannot be changed during "form.post_submit", you should use "form.pre_submit" or "form.submit" instead.');
31+
}
2432
}

0 commit comments

Comments
 (0)
0