Skip to content

Commit

Permalink
minor #19706 [Workflow] Document the EventNameTrait (javiereguiluz)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 7.1 branch.

Discussion
----------

[Workflow] Document the EventNameTrait

Fixes #19694.

Commits
-------

08a12ec [Workflow] Document the EventNameTrait
  • Loading branch information
javiereguiluz committed Mar 27, 2024
2 parents 166d57a + 08a12ec commit f06e595
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion workflow.rst
Expand Up @@ -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
{
Expand All @@ -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::

Expand Down

0 comments on commit f06e595

Please sign in to comment.