Skip to content

Show how to retrieve workflow in a class #12545

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

Closed
wants to merge 1 commit into from
Closed
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
33 changes: 33 additions & 0 deletions workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,39 @@ what actions are allowed on a blog post::

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

In a class or a controller
--------------------------

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

For a controller, you can directly inject it in a method::

use Symfony\Component\Workflow\Registry;

class MyClass
{

private $worflowRegistry;

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

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

// Update the currentState on the post
try {
$workflow->apply($post, 'to_review');
} catch (LogicException $exception) {
// ...
}
// ...
}
}

Using Events
------------
Expand Down