From 08a12ec0616af510e0325a2b21acea467d5ec7fe Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 25 Mar 2024 09:32:21 +0100 Subject: [PATCH] [Workflow] Document the EventNameTrait --- workflow.rst | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/workflow.rst b/workflow.rst index 65c4f827a0f..f0c276a86f1 100644 --- a/workflow.rst +++ b/workflow.rst @@ -496,6 +496,7 @@ workflow leaves a place:: use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Workflow\Event\Event; + use Symfony\Component\Workflow\Event\LeaveEvent; class WorkflowLoggerSubscriber implements EventSubscriberInterface { @@ -518,11 +519,24 @@ workflow leaves a place:: public static function getSubscribedEvents(): array { return [ - 'workflow.blog_publishing.leave' => 'onLeave', + LeaveEvent::getName('blog_publishing') => 'onLeave', + // if you prefer, you can write the event name manually like this: + // 'workflow.blog_publishing.leave' => 'onLeave', ]; } } +.. tip:: + + All built-in workflow events define the ``getName(?string $workflowName, ?string $transitionOrPlaceName)`` + method to build the full event name without having to deal with strings. + You can also use this method in your custom events via the + :class:`Symfony\\Component\\Workflow\\Event\\EventNameTrait`. + + .. versionadded:: 7.1 + + The ``getName()`` method was introduced in Symfony 7.1. + If some listeners update the context during a transition, you can retrieve it via the marking::