Skip to content

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

Closed
wants to merge 4 commits into from
Closed
Changes from 2 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
26 changes: 23 additions & 3 deletions workflow/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[...] were introduced [...]


The following example shows these methods in action:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functions


.. code-block:: twig

Expand All @@ -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(',') }}
Copy link
Member Author

Choose a reason for hiding this comment

The 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 workflow_marked_places()? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! I added your example. Thanks!