Skip to content

[Workflow] Update usage.rst #11400

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions workflow/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ workflow leaves a place::
public function onLeave(Event $event)
{
$this->logger->alert(sprintf(
'Blog post (id: "%s") performed transaction "%s" from "%s" to "%s"',
'Blog post (id: "%s") performed transition "%s" from "%s" to "%s"',
$event->getSubject()->getId(),
$event->getTransition()->getName(),
implode(', ', array_keys($event->getMarking()->getPlaces())),
Expand All @@ -439,7 +439,7 @@ Guard Events
There are a special kind of events called "Guard events". Their event listeners
are invoked every time a call to ``Workflow::can``, ``Workflow::apply`` or
``Workflow::getEnabledTransitions`` is executed. With the guard events you may
add custom logic to decide what transitions that are valid or not. Here is a list
add custom logic to decide what transitions are valid or not. Here is a list
of the guard event names.

* ``workflow.guard``
Expand All @@ -460,15 +460,16 @@ See example to make sure no blog post without title is moved to "review"::
$title = $post->title;

if (empty($title)) {
// Posts with no title should not be allowed
// Posts without title are not allowed
// to perform the transition "to_review"
$event->setBlocked(true);
}
}

public static function getSubscribedEvents()
{
return [
'workflow.blogpost.guard.to_review' => ['guardReview'],
'workflow.blog_publishing.guard.to_review' => ['guardReview'],
];
}
}
Expand Down Expand Up @@ -583,7 +584,7 @@ transition was blocked::
public static function getSubscribedEvents()
{
return [
'workflow.blogpost.guard.publish' => ['guardPublish'],
'workflow.blog_publishing.guard.publish' => ['guardPublish'],
];
}
}
Expand Down Expand Up @@ -618,6 +619,6 @@ You can access the message from a Twig template as follows:
The ``workflow_transition_blockers()`` Twig function was introduced in
Symfony 4.3.

Don't need a human-readable message? You can still use::
Don't need a human-readable message? You can also block a transition via a guard event using::

$event->setBlocked('true');