@@ -361,6 +361,8 @@ name.
361
361
You can find the list of available workflow services with the
362
362
``php bin/console debug:autowiring workflow `` command.
363
363
364
+ .. _workflow_using-events :
365
+
364
366
Using Events
365
367
------------
366
368
@@ -519,6 +521,40 @@ it via the marking::
519
521
// contains the new value
520
522
$marking->getContext();
521
523
524
+ It is also possible to listen to these events by declaring event listeners
525
+ with the following attributes:
526
+
527
+ * :class: `Symfony\\ Component\\ Workflow\\ Attribute\\ AsAnnounceListener `
528
+ * :class: `Symfony\\ Component\\ Workflow\\ Attribute\\ AsCompletedListener `
529
+ * :class: `Symfony\\ Component\\ Workflow\\ Attribute\\ AsEnterListener `
530
+ * :class: `Symfony\\ Component\\ Workflow\\ Attribute\\ AsEnteredListener `
531
+ * :class: `Symfony\\ Component\\ Workflow\\ Attribute\\ AsGuardListener `
532
+ * :class: `Symfony\\ Component\\ Workflow\\ Attribute\\ AsLeaveListener `
533
+ * :class: `Symfony\\ Component\\ Workflow\\ Attribute\\ AsTransitionListener `
534
+
535
+ These attributes do work like the
536
+ :class: `Symfony\\ Component\\ EventDispatcher\\ Attribute\\ AsEventListener `
537
+ attributes::
538
+
539
+ class ArticleWorkflowEventListener
540
+ {
541
+ #[AsTransitionListener(workflow: 'my-workflow', transition: 'published')]
542
+ public function onPublishedTransition(TransitionEvent $event): void
543
+ {
544
+ // ...
545
+ }
546
+
547
+ // ...
548
+ }
549
+
550
+ You may refer to the documentation about
551
+ :ref: `defining event listeners with PHP attributes <event-dispatcher_event-listener-attributes >`
552
+ for further use.
553
+
554
+ .. versionadded :: 6.4
555
+
556
+ The workflow event attributes were introduced in Symfony 6.4.
557
+
522
558
.. _workflow-usage-guard-events :
523
559
524
560
Guard Events
0 commit comments