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 1/2] 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 2/2] 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(); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy