-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Added docs for workflow_marked_places() function #7820
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -249,9 +249,26 @@ This class has two more methods: | |
Usage in Twig | ||
------------- | ||
|
||
Using your workflow in your Twig templates reduces the need of domain logic | ||
in the view layer. Consider this example of the control panel of the blog. | ||
The links below will only be displayed when the action is allowed: | ||
Symfony defines several Twig functions to manage workflows and reduce the need | ||
of domain logic in your templates: | ||
|
||
``workflow_can()`` | ||
Returns ``true`` if the given object can make the given transition. | ||
|
||
``workflow_transitions()`` | ||
Returns an array with all the transitions enabled for the given object. | ||
|
||
``workflow_marked_places()`` | ||
Returns an array with the place names of the given marking. | ||
|
||
``workflow_has_marked_place()`` | ||
Returns ``true`` if the marking of the given object has the given state. | ||
|
||
.. versionadded:: 3.3 | ||
The ``workflow_marked_places()`` and ``workflow_has_marked_place()`` | ||
functions were added in Symfony 3.3. | ||
|
||
The following example shows these methods in action: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. functions |
||
|
||
.. code-block:: twig | ||
|
||
|
@@ -277,3 +294,6 @@ The links below will only be displayed when the action is allowed: | |
{% if workflow_has_marked_place(post, 'to_review') %} | ||
<p>This post is ready for review.</p> | ||
{% endif %} | ||
|
||
{# Get all the places related to the 'post' marking #} | ||
{{ workflow_marked_places(post)|join(',') }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This example is pretty stupid. Can you please suggest me an interesting and realistic example for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about something like: {% if 'waiting_some_approval' in workflow_marked_places(post) %}
<span class="special-label"></span>
{% endif %} Many places may be needed for a "can", but some times, only one to display things. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very nice! I added your example. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[...] were introduced [...]