Skip to content

Added note regarding workflow "entered" event being dispatched on creation #12740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2019
Merged
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
17 changes: 11 additions & 6 deletions workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,29 +215,29 @@ what actions are allowed on a blog post::

// See all the available transitions for the post in the current state
$transitions = $workflow->getEnabledTransitions($post);

Accessing the Workflow in a Class
---------------------------------

To access workflow inside a class, use dependency injection and inject the
registry in the constructor::

use Symfony\Component\Workflow\Registry;

class MyClass
{

private $workflowRegistry;

public function __construct(Registry $workflowRegistry)
{
$this->workflowRegistry = $workflowRegistry;
}

public function toReview(BlogPost $blogPost)
{
$workflow = $this->workflowRegistry->get($blogPost);

// Update the currentState on the post
try {
$workflow->apply($post, 'to_review');
Expand Down Expand Up @@ -339,6 +339,11 @@ order:
The leaving and entering events are triggered even for transitions that stay
in same place.

.. versionadded:: 4.3

Following events are also dispatched when the subject enters the workflow
for the first time: ``workflow.entered`` and ``workflow.[worflow name].entered``.

Here is an example of how to enable logging for every time a "blog_publishing"
workflow leaves a place::

Expand Down