File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -215,6 +215,39 @@ what actions are allowed on a blog post::
215215
216216 // See all the available transitions for the post in the current state
217217 $transitions = $workflow->getEnabledTransitions($post);
218+
219+ In a class or a controller
220+ --------------------------
221+
222+ To access workflow inside a class, use dependency injection and inject the registry in the constructor.
223+
224+ For a controller, you can directly inject it in a method::
225+
226+ use Symfony\Component\Workflow\Registry;
227+
228+ class MyClass
229+ {
230+
231+ private $worflowRegistry;
232+
233+ public function __construct(Registry $workflowRegistry)
234+ {
235+ $this->worflowRegistry = $worflowRegistry;
236+ }
237+
238+ public function toReview(BlogPost $blogPost)
239+ {
240+ $workflow = $this->worflowRegistry->get($blogPost);
241+
242+ // Update the currentState on the post
243+ try {
244+ $workflow->apply($post, 'to_review');
245+ } catch (LogicException $exception) {
246+ // ...
247+ }
248+ // ...
249+ }
250+ }
218251
219252Using Events
220253------------
You can’t perform that action at this time.
0 commit comments