@@ -361,6 +361,8 @@ name.
361361 You can find the list of available workflow services with the
362362 ``php bin/console debug:autowiring workflow `` command.
363363
364+ .. _workflow_using-events :
365+
364366Using Events
365367------------
366368
@@ -519,6 +521,44 @@ it via the marking::
519521 // contains the new value
520522 $marking->getContext();
521523
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+
522562.. _workflow-usage-guard-events :
523563
524564Guard Events
0 commit comments