@@ -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,44 @@ 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 ArticleWorfklowEventListener
540
+ {
541
+ public function __construct()
542
+ {
543
+ }
544
+
545
+ #[AsTransitionListener(workflow: 'my-workflow', transition: 'published')]
546
+ public function onPublishedTransition(TransitionEvent $event): void
547
+ {
548
+ // ...
549
+ }
550
+
551
+ // ...
552
+ }
553
+
554
+ You may refer to the documentation about
555
+ :ref: `defining event listeners with PHP attributes <event-dispatcher_event-listener-attributes >`
556
+ for further use.
557
+
558
+ .. versionadded :: 6.4
559
+
560
+ The workflow event attributes were introduced in Symfony 6.4.
561
+
522
562
.. _workflow-usage-guard-events :
523
563
524
564
Guard Events
0 commit comments