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

Skip to content

[Form] Deprecate FormEvent::setData() for events that do not allow it #51043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UPGRADE-6.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Form

* Deprecate using `DateTime` or `DateTimeImmutable` model data with a different timezone than configured with the
`model_timezone` option in `DateType`, `DateTimeType`, and `TimeType`
* Deprecate `PostSetDataEvent::setData()`, use `PreSetDataEvent::setData()` instead
* Deprecate `PostSubmitEvent::setData()`, use `PreSubmitDataEvent::setData()` or `SubmitDataEvent::setData()` instead

FrameworkBundle
---------------
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ CHANGELOG

* Deprecate using `DateTime` or `DateTimeImmutable` model data with a different timezone than configured with the
`model_timezone` option in `DateType`, `DateTimeType`, and `TimeType`
* Deprecate `PostSetDataEvent::setData()`, use `PreSetDataEvent::setData()` instead
* Deprecate `PostSubmitEvent::setData()`, use `PreSubmitDataEvent::setData()` or `SubmitDataEvent::setData()` instead

6.3
---
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/Form/Event/PostSetDataEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Form\Event;

use Symfony\Component\Form\Exception\BadMethodCallException;
use Symfony\Component\Form\FormEvent;

/**
Expand All @@ -20,4 +21,12 @@
*/
final class PostSetDataEvent extends FormEvent
{
/**
* @deprecated since Symfony 6.4, it will throw an exception in 7.0.
*/
public function setData(mixed $data): void
{
trigger_deprecation('symfony/form', '6.4', 'Calling "%s()" will throw an exception as of 7.0, listen to "form.pre_set_data" instead.', __METHOD__);
// throw new BadMethodCallException('Form data cannot be changed during "form.post_set_data", you should use "form.pre_set_data" instead.');
}
}
8 changes: 8 additions & 0 deletions src/Symfony/Component/Form/Event/PostSubmitEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@
*/
final class PostSubmitEvent extends FormEvent
{
/**
* @deprecated since Symfony 6.4, it will throw an exception in 7.0.
*/
public function setData(mixed $data): void
{
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__);
// throw new BadMethodCallException('Form data cannot be changed during "form.post_submit", you should use "form.pre_submit" or "form.submit" instead.');
}
}