Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions components/workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 workflow, you can simply call ``getMarking``::

// ...
$blogPost = new BlogPost();
$workflow = $registry->get($blogPost);

// initiate workflow
$workflow->getMarking($blogPost);


Learn more
----------

Expand Down
15 changes: 15 additions & 0 deletions workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand Down