Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a8ce04

Browse files
epitrewouterj
authored andcommitted
Added explaination on context in events and initial marking
1 parent 6bd8350 commit 5a8ce04

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

workflow.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,36 @@ order:
381381
* ``workflow.[workflow name].announce``
382382
* ``workflow.[workflow name].announce.[transition name]``
383383

384+
You can avoid triggering those events by using the context::
385+
386+
$workflow->apply($subject, $transitionName, [Workflow::DISABLE_ANNOUNCE_EVENT => true]);
387+
388+
.. versionadded:: 5.1
389+
390+
The ``Workflow::DISABLE_ANNOUNCE_EVENT`` constant was introduced in Symfony 5.1.
391+
392+
.. versionadded:: 5.2
393+
394+
In Symfony 5.2, the context is accessible in all events::
395+
396+
// $context must be an array
397+
$context = ['context_key' => 'context_value'];
398+
$workflow->apply($subject, $transitionName, $context);
399+
400+
// in an event listener
401+
$context = $event->getContext(); // returns ['context']
402+
384403
.. note::
385404

386405
The leaving and entering events are triggered even for transitions that stay
387406
in same place.
388407

408+
.. note::
409+
410+
If you initialize the marking by calling ``$workflow->getMarking($object);``,
411+
then the ``workflow.[workflow_name].entered.[initial_place_name]`` event will
412+
be called with the default context (``Workflow::DEFAULT_INITIAL_CONTEXT``).
413+
389414
Here is an example of how to enable logging for every time a "blog_publishing"
390415
workflow leaves a place::
391416

0 commit comments

Comments
 (0)