Skip to content

Commit acf6012

Browse files
[Workflow] Add PHP attributes to register listeners and guards
1 parent d476a49 commit acf6012

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

reference/attributes.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ Each validation constraint comes with a PHP attribute. See
117117

118118
* :doc:`HasNamedArgument </validation/custom_constraint>`
119119

120+
Workflow
121+
~~~~~~~~
122+
123+
* :ref:`AsAnnounceListener <workflow_using-events>`
124+
* :ref:`AsCompletedListener <workflow_using-events>`
125+
* :ref:`AsEnterListener <workflow_using-events>`
126+
* :ref:`AsEnteredListener <workflow_using-events>`
127+
* :ref:`AsGuardListener <workflow_using-events>`
128+
* :ref:`AsLeaveListener <workflow_using-events>`
129+
* :ref:`AsTransitionListener <workflow_using-events>`
130+
120131
.. _`AsEntityAutocompleteField`: https://symfony.com/bundles/ux-autocomplete/current/index.html#usage-in-a-form-with-ajax
121132
.. _`AsLiveComponent`: https://symfony.com/bundles/ux-live-component/current/index.html
122133
.. _`AsTwigComponent`: https://symfony.com/bundles/ux-twig-component/current/index.html

workflow.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
364366
Using Events
365367
------------
366368

@@ -519,6 +521,40 @@ 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 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+
522558
.. _workflow-usage-guard-events:
523559

524560
Guard Events

0 commit comments

Comments
 (0)