From 82a94f7dda855dd23b8e2e6835d8816f000c092f Mon Sep 17 00:00:00 2001 From: Carlos Pereira De Amorim Date: Thu, 9 Jul 2020 12:50:34 +0200 Subject: [PATCH 01/10] Added explaination on context in events and initial marking --- components/workflow.rst | 10 ++++++++++ workflow.rst | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/components/workflow.rst b/components/workflow.rst index a35602f1ac2..17fc46547f8 100644 --- a/components/workflow.rst +++ b/components/workflow.rst @@ -94,6 +94,16 @@ you can retrieve a workflow from it and use it as follows:: $workflow->can($blogPost, 'publish'); // True $workflow->getEnabledTransitions($blogPost); // $blogPost can perform transition "publish" or "reject" +If you want to initiate your worflow, you can simply call ``getMarking``:: + + // ... + $blogPost = new BlogPost(); + $workflow = $registry->get($blogPost); + + // initiate workflow + $workflow->getMarking($blogPost); + + Learn more ---------- diff --git a/workflow.rst b/workflow.rst index 376996534ba..34deac2ad9e 100644 --- a/workflow.rst +++ b/workflow.rst @@ -356,11 +356,26 @@ order: The ``Workflow::DISABLE_ANNOUNCE_EVENT`` constant was introduced in Symfony 5.1. + .. versionadded:: 5.2 + + The context will be accessible in all the events:: + + // $context must be an array + $context = ['context']; + $workflow->apply($subject, $transitionName, $context); + + // in an event listener + $context = $event->getContext(); // returns ['context'] + .. note:: The leaving and entering events are triggered even for transitions that stay in same place. +.. note:: + + If you initialize the marking by calling ``$workflow->getMarking($object);``, then the ``workflow.[workflow name].entered.[initial place name]`` will be called with a default context ``Workflow::DEFAULT_INITIAL_CONTEXT`` + Here is an example of how to enable logging for every time a "blog_publishing" workflow leaves a place:: From a3fd74970d51e7fd6fd51e5574bb5b875eb18061 Mon Sep 17 00:00:00 2001 From: Carlos Pereira De Amorim Date: Sat, 11 Jul 2020 22:29:40 +0200 Subject: [PATCH 02/10] typo --- components/workflow.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/workflow.rst b/components/workflow.rst index 17fc46547f8..f27e55ca2d3 100644 --- a/components/workflow.rst +++ b/components/workflow.rst @@ -94,7 +94,7 @@ you can retrieve a workflow from it and use it as follows:: $workflow->can($blogPost, 'publish'); // True $workflow->getEnabledTransitions($blogPost); // $blogPost can perform transition "publish" or "reject" -If you want to initiate your worflow, you can simply call ``getMarking``:: +If you want to initiate your workflow, you can simply call ``getMarking``:: // ... $blogPost = new BlogPost(); From c0062eaa984cbf57c8fd57209fbbdadb695fc19d Mon Sep 17 00:00:00 2001 From: Carlos Pereira De Amorim Date: Tue, 8 Dec 2020 14:33:15 +0100 Subject: [PATCH 03/10] Update workflow.rst --- components/workflow.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/workflow.rst b/components/workflow.rst index f27e55ca2d3..d6e4b9711ec 100644 --- a/components/workflow.rst +++ b/components/workflow.rst @@ -94,7 +94,7 @@ you can retrieve a workflow from it and use it as follows:: $workflow->can($blogPost, 'publish'); // True $workflow->getEnabledTransitions($blogPost); // $blogPost can perform transition "publish" or "reject" -If you want to initiate your workflow, you can simply call ``getMarking``:: +If you want to initiate your workflow, you can call ``getMarking``:: // ... $blogPost = new BlogPost(); From 3e7f249783812126398cda4ca534ac999738d611 Mon Sep 17 00:00:00 2001 From: Carlos Pereira De Amorim Date: Tue, 8 Dec 2020 14:35:15 +0100 Subject: [PATCH 04/10] Update workflow.rst --- workflow.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workflow.rst b/workflow.rst index 74603bef257..d4322cd3bad 100644 --- a/workflow.rst +++ b/workflow.rst @@ -388,7 +388,7 @@ order: .. versionadded:: 5.2 - The context will be accessible in all the events:: + In Symfony 5.2, the context is accessible in all events:: // $context must be an array $context = ['context']; From 1bd334a12375f2d91bc5ec36898d6bbdf4aed26c Mon Sep 17 00:00:00 2001 From: Carlos Pereira De Amorim Date: Tue, 8 Dec 2020 14:49:37 +0100 Subject: [PATCH 05/10] Update workflow.rst --- workflow.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workflow.rst b/workflow.rst index d4322cd3bad..959b5be1be5 100644 --- a/workflow.rst +++ b/workflow.rst @@ -404,7 +404,7 @@ order: .. note:: - If you initialize the marking by calling ``$workflow->getMarking($object);``, then the ``workflow.[workflow name].entered.[initial place name]`` will be called with a default context ``Workflow::DEFAULT_INITIAL_CONTEXT`` + If you initialize the marking by calling ``$workflow->getMarking($object);``, then the ``workflow.[workflow name].entered.[initial place name]`` event will be called with a default context ``Workflow::DEFAULT_INITIAL_CONTEXT``. Here is an example of how to enable logging for every time a "blog_publishing" workflow leaves a place:: From 3ec919783a32bc4daf1dcd194afccc8e9c15a165 Mon Sep 17 00:00:00 2001 From: Carlos Pereira De Amorim Date: Tue, 8 Dec 2020 22:37:27 +0100 Subject: [PATCH 06/10] Update workflow.rst --- components/workflow.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/workflow.rst b/components/workflow.rst index d6e4b9711ec..40e19fb2548 100644 --- a/components/workflow.rst +++ b/components/workflow.rst @@ -94,6 +94,9 @@ you can retrieve a workflow from it and use it as follows:: $workflow->can($blogPost, 'publish'); // True $workflow->getEnabledTransitions($blogPost); // $blogPost can perform transition "publish" or "reject" +Initialization +-------------- + If you want to initiate your workflow, you can call ``getMarking``:: // ... From a4fce22c0b7006053fa9ab92ff02d74956a978d4 Mon Sep 17 00:00:00 2001 From: Carlos Pereira De Amorim Date: Tue, 8 Dec 2020 22:38:11 +0100 Subject: [PATCH 07/10] Update workflow.rst Co-authored-by: Antoine Makdessi --- workflow.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workflow.rst b/workflow.rst index 959b5be1be5..f873f77058c 100644 --- a/workflow.rst +++ b/workflow.rst @@ -391,7 +391,7 @@ order: In Symfony 5.2, the context is accessible in all events:: // $context must be an array - $context = ['context']; + $context = ['context_key' => 'context_value']; $workflow->apply($subject, $transitionName, $context); // in an event listener From 7b0d11828d0c999bdcd53e81c12b69822edad8c5 Mon Sep 17 00:00:00 2001 From: Carlos Pereira De Amorim Date: Tue, 22 Dec 2020 14:18:44 +0100 Subject: [PATCH 08/10] Update components/workflow.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Grégoire Pineau --- components/workflow.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/workflow.rst b/components/workflow.rst index 40e19fb2548..ddbc3fe351f 100644 --- a/components/workflow.rst +++ b/components/workflow.rst @@ -97,7 +97,7 @@ you can retrieve a workflow from it and use it as follows:: Initialization -------------- -If you want to initiate your workflow, you can call ``getMarking``:: +If you want to initiate your workflow, you can call ``getMarking()`` method:: // ... $blogPost = new BlogPost(); From d6480bb1dca8d0d71bb75e71227676d2b32f7d8a Mon Sep 17 00:00:00 2001 From: Carlos Pereira De Amorim Date: Tue, 22 Dec 2020 14:19:51 +0100 Subject: [PATCH 09/10] Update workflow.rst --- components/workflow.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/components/workflow.rst b/components/workflow.rst index ddbc3fe351f..16a465202ec 100644 --- a/components/workflow.rst +++ b/components/workflow.rst @@ -106,7 +106,6 @@ If you want to initiate your workflow, you can call ``getMarking()`` method:: // initiate workflow $workflow->getMarking($blogPost); - Learn more ---------- From a8961ba3f3359e651a4acb6c47bb7663f98803fc Mon Sep 17 00:00:00 2001 From: Carlos Pereira De Amorim Date: Tue, 22 Dec 2020 16:31:55 +0100 Subject: [PATCH 10/10] Update workflow.rst --- components/workflow.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/workflow.rst b/components/workflow.rst index 16a465202ec..8cedf2dbeed 100644 --- a/components/workflow.rst +++ b/components/workflow.rst @@ -97,7 +97,7 @@ you can retrieve a workflow from it and use it as follows:: Initialization -------------- -If you want to initiate your workflow, you can call ``getMarking()`` method:: +If the property of your object is null and you want to set it with the `initial_marking` from the configuration, you can call the `getMarking()` method to initialize the object property:: // ... $blogPost = new BlogPost();