Skip to content

Commit a7c7c18

Browse files
committed
minor #19206 [Form] Updating the generic FormEvent to specific event (e.g. `PreS… (ThomasLandauer)
This PR was merged into the 6.4 branch. Discussion ---------- [Form] Updating the generic `FormEvent` to specific event (e.g. `PreS… …etDataEvent`) Closes: symfony/symfony#52829 Page: https://symfony.com/doc/6.4/form/events.html The idea is taken from symfony/symfony#52829 (comment) Commits ------- f65d2f4 [Form] Updating the generic `FormEvent` to specific event (e.g. `PreSetDataEvent`)
2 parents 472aaf8 + f65d2f4 commit a7c7c18

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

form/events.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ A) The ``FormEvents::PRE_SET_DATA`` Event
6262
The ``FormEvents::PRE_SET_DATA`` event is dispatched at the beginning of the
6363
``Form::setData()`` method. It is used to modify the data given during
6464
pre-population with
65-
:method:`FormEvent::setData() <Symfony\\Component\\Form\\FormEvent::setData>`.
65+
:method:`PreSetData::setData() <Symfony\\Component\\Form\\Event\\PreSetDataEvent>`.
6666
The method :method:`Form::setData() <Symfony\\Component\\Form\\Form::setData>`
6767
is locked since the event is dispatched from it and will throw an exception
6868
if called from a listener.
@@ -277,13 +277,13 @@ method of the ``FormFactory``::
277277
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
278278
use Symfony\Component\Form\Extension\Core\Type\EmailType;
279279
use Symfony\Component\Form\Extension\Core\Type\TextType;
280-
use Symfony\Component\Form\FormEvent;
280+
use Symfony\Component\Form\Event\PreSubmitEvent;
281281
use Symfony\Component\Form\FormEvents;
282282

283283
$form = $formFactory->createBuilder()
284284
->add('username', TextType::class)
285285
->add('showEmail', CheckboxType::class)
286-
->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event): void {
286+
->addEventListener(FormEvents::PRE_SUBMIT, function (PreSubmitEvent $event): void {
287287
$user = $event->getData();
288288
$form = $event->getForm();
289289

@@ -313,7 +313,7 @@ callback for better readability::
313313

314314
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
315315
use Symfony\Component\Form\Extension\Core\Type\TextType;
316-
use Symfony\Component\Form\FormEvent;
316+
use Symfony\Component\Form\Event\PreSetDataEvent;
317317
use Symfony\Component\Form\FormEvents;
318318

319319
// ...
@@ -331,7 +331,7 @@ callback for better readability::
331331
;
332332
}
333333

334-
public function onPreSetData(FormEvent $event): void
334+
public function onPreSetData(PreSetDataEvent $event): void
335335
{
336336
// ...
337337
}
@@ -353,7 +353,8 @@ Consider the following example of a form event subscriber::
353353

354354
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
355355
use Symfony\Component\Form\Extension\Core\Type\EmailType;
356-
use Symfony\Component\Form\FormEvent;
356+
use Symfony\Component\Form\Event\PreSetDataEvent;
357+
use Symfony\Component\Form\Event\PreSubmitEvent;
357358
use Symfony\Component\Form\FormEvents;
358359

359360
class AddEmailFieldListener implements EventSubscriberInterface
@@ -366,7 +367,7 @@ Consider the following example of a form event subscriber::
366367
];
367368
}
368369

369-
public function onPreSetData(FormEvent $event): void
370+
public function onPreSetData(PreSetDataEvent $event): void
370371
{
371372
$user = $event->getData();
372373
$form = $event->getForm();
@@ -378,7 +379,7 @@ Consider the following example of a form event subscriber::
378379
}
379380
}
380381

381-
public function onPreSubmit(FormEvent $event): void
382+
public function onPreSubmit(PreSubmitEvent $event): void
382383
{
383384
$user = $event->getData();
384385
$form = $event->getForm();

0 commit comments

Comments
 (0)