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