From db72c63079eb9ef48ac13d61c544a6f0c0e23e81 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 19 Apr 2017 10:07:19 +0200 Subject: [PATCH 1/4] Added docs for workflow_marked_places() function --- workflow/usage.rst | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/workflow/usage.rst b/workflow/usage.rst index 7f6ce9d9f36..2d37519791b 100644 --- a/workflow/usage.rst +++ b/workflow/usage.rst @@ -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()`` methods + were added in Symfony 3.3. + +The following example shows these methods in action: .. 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') %}

This post is ready for review.

{% endif %} + + {# Get all the places related to the 'post' marking #} + {{ workflow_marked_places(post)|join(',') }} From e2ded36321540b092677adfd7a118fd46b0d4a8a Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 19 Apr 2017 10:09:30 +0200 Subject: [PATCH 2/4] Minor fix --- workflow/usage.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/workflow/usage.rst b/workflow/usage.rst index 2d37519791b..ca2ac459d60 100644 --- a/workflow/usage.rst +++ b/workflow/usage.rst @@ -265,8 +265,8 @@ of domain logic in your templates: 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()`` methods - were added in Symfony 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: From 20b65ac6c71198f38faf67e3a7625c8721ab17e0 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 19 Apr 2017 20:38:41 +0200 Subject: [PATCH 3/4] Minor fixes --- workflow/usage.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/workflow/usage.rst b/workflow/usage.rst index ca2ac459d60..f81945c94bb 100644 --- a/workflow/usage.rst +++ b/workflow/usage.rst @@ -266,9 +266,9 @@ of domain logic in your templates: .. versionadded:: 3.3 The ``workflow_marked_places()`` and ``workflow_has_marked_place()`` - functions were added in Symfony 3.3. + functions were introduced in Symfony 3.3. -The following example shows these methods in action: +The following example shows these functions in action: .. code-block:: twig From aee3deb67a86b6def6b3181a5180774765403d6d Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 20 Apr 2017 09:43:31 +0200 Subject: [PATCH 4/4] Improved the example --- workflow/usage.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/workflow/usage.rst b/workflow/usage.rst index f81945c94bb..5dfa1f0cab5 100644 --- a/workflow/usage.rst +++ b/workflow/usage.rst @@ -295,5 +295,7 @@ The following example shows these functions in action:

This post is ready for review.

{% endif %} - {# Get all the places related to the 'post' marking #} - {{ workflow_marked_places(post)|join(',') }} + {# Check if some place has been marked on the object #} + {% if 'waiting_some_approval' in workflow_marked_places(post) %} + PENDING + {% endif %}