@@ -265,6 +265,39 @@ registry in the constructor::
265
265
}
266
266
}
267
267
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
+
268
301
Using Events
269
302
------------
270
303
@@ -665,7 +698,7 @@ of domain logic in your templates:
665
698
666
699
``workflow_has_marked_place() ``
667
700
Returns ``true `` if the marking of the given object has the given state.
668
-
701
+
669
702
``workflow_transition_blockers() ``
670
703
Returns :class: `Symfony\\ Component\\ Workflow\\ TransitionBlockerList ` for the given transition.
671
704
@@ -700,7 +733,7 @@ The following example shows these functions in action:
700
733
{% if 'reviewed' in workflow_marked_places(post) %}
701
734
<span class="label">Reviewed</span>
702
735
{% endif %}
703
-
736
+
704
737
{# Loop through the transition blockers #}
705
738
{% for blocker in workflow_transition_blockers(post, 'publish') %}
706
739
<span class="error">{{ blocker.message }}</span>
@@ -869,7 +902,7 @@ In a :ref:`flash message <flash-messages>` in your controller::
869
902
870
903
// $transition = ...; (an instance of Transition)
871
904
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)
873
906
$title = $workflow->getMetadataStore()->getMetadata('title', $transition);
874
907
$this->addFlash('info', "You have successfully applied the transition with title: '$title'");
875
908
0 commit comments