You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
@@ -210,7 +210,7 @@ When a state transition is initiated, the events are dispatched in the following
order:
``workflow.guard``
Validate whether the transition isallowed at all (:ref:`see below <workflow-usage-guard-events>`).
Validate whether the transition isblocked or not (:ref:`see below <workflow-usage-guard-events>` and :ref:`using guards <workflow-usage-using-guards>`).
The three events being dispatched are:
Expand DownExpand Up
@@ -322,14 +322,14 @@ 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 decidewhat transitionsare valid or not. Here is a list
add custom logic to decidewhich transitionsshould be blocked or not. Here is a list
The component has a guard logic to control the execution of your workflow on top of your configuration.
It allows you to execute your custom logic to decide if the transition is blocked or not, before actually
applying this transition.
You have multiple optional ways to use guards in your workflow.
The first way is :ref:`with the guard event <workflow-usage-guard-events>`, which allows you to implement
any desired feature.
Another one is via the configuration and its specific entry ``guard`` on a transition.
This ``guard`` entry allows any expression that is valid for the Expression Language component:
.. configuration-block::
.. code-block:: yaml
# config/packages/workflow.yaml
framework:
workflows:
blog_publishing:
# previous configuration
transitions:
to_review:
# the transition is allowed only if the current user has the ROLE_REVIEWER role.
guard: "is_granted('ROLE_REVIEWER')"
from: draft
to: reviewed
publish:
# or "is_anonymous", "is_remember_me", "is_fully_authenticated", "is_granted"
guard: "is_authenticated"
from: reviewed
to: published
reject:
# or any valid expression language with "subject" refering to the post
guard: "has_role("ROLE_ADMIN") and subject.isStatusReviewed()"
from: reviewed
to: rejected
Usage in Twig
-------------
Expand DownExpand Up
@@ -434,7 +479,7 @@ The following example shows these functions in action:
{% endfor %}
{# Check if the object is in some specific place #}
{% if workflow_has_marked_place(post, 'review') %}
{% if workflow_has_marked_place(post, 'reviewed') %}
<p>This post is ready for review.</p>
{% endif %}
Expand Down
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.