Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Workflow] Document the EventNameTrait #19706

Merged
merged 1 commit into from Mar 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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',
OskarStark marked this conversation as resolved.
Show resolved Hide resolved
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