8000 [Form] Use `form.post_set_data` in `ResizeFormListener` · symfony/symfony@0967026 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0967026

Browse files
committed
[Form] Use form.post_set_data in ResizeFormListener
1 parent 68f27ef commit 0967026

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

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+
* Use `form.post_set_data` instead of `form.pre_set_data` in `ResizeFormListener`
10+
* Change the priority of `DataCollectorListener` from 255 to -255
911

1012
6.3
1113
---

src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Form\Extension\Core\EventListener;
1313

1414
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
15+
use Symfony\Component\Form\Event\PostSetDataEvent;
1516
use Symfony\Component\Form\Exception\UnexpectedTypeException;
1617
use Symfony\Component\Form\FormEvent;
1718
use Symfony\Component\Form\FormEvents;
@@ -45,14 +46,16 @@ public function __construct(string $type, array $options = [], bool $allowAdd =
4546
public static function getSubscribedEvents(): array
4647
{
4748
return [
48-
FormEvents::PRE_SET_DATA => 'preSetData',
49+
FormEvents::POST_SET_DATA => ['postSetData', 255], // as early as possible
4950
FormEvents::PRE_SUBMIT => 'preSubmit',
5051
// (MergeCollectionListener, MergeDoctrineCollectionListener)
5152
FormEvents::SUBMIT => ['onSubmit', 50],
5253
];
5354
}
5455

5556
/**
57+
* @deprecated Since 6.4, use {@see postSetData()} instead.
58+
*
5659
* @return void
5760
*/
5861
public function preSetData(FormEvent $event)
@@ -77,6 +80,11 @@ public function preSetData(FormEvent $event)
7780
}
7881
}
7982

83+
public function postSetData(PostSetDataEvent $event): void
84+
{
85+
$this->preSetData($event);
86+
}
87+
8088
/**
8189
* @return void
8290
*/

src/Symfony/Component/Form/Extension/DataCollector/EventListener/DataCollectorListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public function __construct(FormDataCollectorInterface $dataCollector)
3434
public static function getSubscribedEvents(): array
3535
{
3636
return [
37-
// High priority in order to be called as soon as possible
38-
FormEvents::POST_SET_DATA => ['postSetData', 255],
37+
// Low priority in order to be called as late as possible
38+
FormEvents::POST_SET_DATA => ['postSetData', -255],
3939
// Low priority in order to be called as late as possible
4040
FormEvents::POST_SUBMIT => ['postSubmit', -255],
4141
];

0 commit comments

Comments
 (0)
0