@@ -265,6 +265,39 @@ registry in the constructor::
265265 }
266266 }
267267
268+ Or use the typed + named parameter injection::
269+
270+ use App\Entity\BlogPost;
271+ use Symfony\Component\Workflow\WorkflowInterface;
272+
273+ class MyClass
274+ {
275+ private $blogPostWorkflow;
276+
277+ public function __construct(WorkflowInterface $blogPostWorkflow)
278+ {
279+ $this->blogPostWorkflow = $blogPostWorkflow;
280+ }
281+
282+ public function toReview(BlogPost $post)
283+ {
284+ // Update the currentState on the post
285+ try {
286+ $this->blogPostWorkflow->apply($post, 'to_review');
287+ } catch (LogicException $exception) {
288+ // ...
289+ }
290+ // ...
291+ }
292+ }
293+
294+ .. tip ::
295+
296+ You can find the list of available services with the following command::
297+
298+ php bin/console debug:autowiring workflow
299+
300+
268301Using Events
269302------------
270303
@@ -665,7 +698,7 @@ of domain logic in your templates:
665698
666699``workflow_has_marked_place() ``
667700 Returns ``true `` if the marking of the given object has the given state.
668-
701+
669702``workflow_transition_blockers() ``
670703 Returns :class: `Symfony\\ Component\\ Workflow\\ TransitionBlockerList ` for the given transition.
671704
@@ -700,7 +733,7 @@ The following example shows these functions in action:
700733 {% if 'reviewed' in workflow_marked_places(post) %}
701734 <span class="label">Reviewed</span>
702735 {% endif %}
703-
736+
704737 {# Loop through the transition blockers #}
705738 {% for blocker in workflow_transition_blockers(post, 'publish') %}
706739 <span class="error">{{ blocker.message }}</span>
@@ -869,7 +902,7 @@ In a :ref:`flash message <flash-messages>` in your controller::
869902
870903 // $transition = ...; (an instance of Transition)
871904
872- // $workflow is a Workflow instance retrieved from the Registry (see above)
905+ // $workflow is a Workflow instance retrieved from the Registry or injected directly (see above)
873906 $title = $workflow->getMetadataStore()->getMetadata('title', $transition);
874907 $this->addFlash('info', "You have successfully applied the transition with title: '$title'");
875908
0 commit comments