Skip to content

Commit 692ca8b

Browse files
committed
Added explaination on context in events and initial marking
1 parent 57e3020 commit 692ca8b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

components/workflow.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ you can retrieve a workflow from it and use it as follows::
9494
$workflow->can($blogPost, 'publish'); // True
9595
$workflow->getEnabledTransitions($blogPost); // $blogPost can perform transition "publish" or "reject"
9696

97+
If you want to initiate your worflow, you can simply call ``getMarking``::
98+
99+
// ...
100+
$blogPost = new BlogPost();
101+
$workflow = $registry->get($blogPost);
102+
103+
// initiate workflow
104+
$workflow->getMarking($blogPost);
105+
106+
107+
97108
Learn more
98109
----------
99110

workflow.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,26 @@ order:
356356

357357
The ``Workflow::DISABLE_ANNOUNCE_EVENT`` constant was introduced in Symfony 5.1.
358358

359+
.. versionadded:: 5.2
360+
361+
The context will be accessible in all the events::
362+
363+
// $context must be an array
364+
$context = ['context'];
365+
$workflow->apply($subject, $transitionName, $context);
366+
367+
// in an event listener
368+
$context = $event->getContext(); // returns ['context']
369+
359370
.. note::
360371

361372
The leaving and entering events are triggered even for transitions that stay
362373
in same place.
363374

375+
.. note::
376+
377+
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 marking ``Workflow::DEFAULT_INITIAL_CONTEXT``
378+
364379
Here is an example of how to enable logging for every time a "blog_publishing"
365380
workflow leaves a place::
366381

0 commit comments

Comments
 (0)