@@ -165,9 +165,12 @@ like this:
165
165
166
166
The configured property will be used via it's implemented getter/setter methods by the marking store::
167
167
168
+ // src/Entity/BlogPost.php
169
+ namespace App\Entity;
170
+
168
171
class BlogPost
169
172
{
170
- // the configured property must be declared
173
+ // the configured marking store property must be declared
171
174
private $currentPlace;
172
175
private $title;
173
176
private $content;
@@ -236,11 +239,11 @@ Accessing the Workflow in a Class
236
239
To access workflow inside a class, use dependency injection and inject the
237
240
registry in the constructor::
238
241
242
+ use App\Entity\BlogPost;
239
243
use Symfony\Component\Workflow\Registry;
240
244
241
245
class MyClass
242
246
{
243
-
244
247
private $workflowRegistry;
245
248
246
249
public function __construct(Registry $workflowRegistry)
@@ -361,11 +364,15 @@ order:
361
364
Here is an example of how to enable logging for every time a "blog_publishing"
362
365
workflow leaves a place::
363
366
367
+ // src/App/EventSubscriber/WorkflowLoggerSubscriber.php
368
+
369
+ namespace App\EventSubscriber;
370
+
364
371
use Psr\Log\LoggerInterface;
365
372
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
366
373
use Symfony\Component\Workflow\Event\Event;
367
374
368
- class WorkflowLogger implements EventSubscriberInterface
375
+ class WorkflowLoggerSubscriber implements EventSubscriberInterface
369
376
{
370
377
private $logger;
371
378
@@ -411,14 +418,19 @@ list of the guard event names.
411
418
This example stops any blog post being transitioned to "reviewed" if it is
412
419
missing a title::
413
420
421
+ // src/App/EventSubscriber/BlogPostReviewSubscriber.php
422
+
423
+ namespace App\EventSubscriber;
424
+
425
+ use App\Entity\BlogPost;
414
426
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
415
427
use Symfony\Component\Workflow\Event\GuardEvent;
416
428
417
- class BlogPostReviewListener implements EventSubscriberInterface
429
+ class BlogPostReviewSubscriber implements EventSubscriberInterface
418
430
{
419
431
public function guardReview(GuardEvent $event)
420
432
{
421
- /** @var App\Entity\ BlogPost $post */
433
+ /** @var BlogPost $post */
422
434
$post = $event->getSubject();
423
435
$title = $post->title;
424
436
@@ -600,13 +612,14 @@ This example has been simplified; in production you may prefer to use the
600
612
:doc: `Translation </translation >` component to manage messages in one
601
613
place::
602
614
603
- namespace App\Listener\Workflow\Task;
615
+ // src/App/EventSubscriber/BlogPostPublishSubscriber.php
616
+ namespace App\EventSubscriber;
604
617
605
618
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
606
619
use Symfony\Component\Workflow\Event\GuardEvent;
607
620
use Symfony\Component\Workflow\TransitionBlocker;
608
621
609
- class BlogPostPublishListener implements EventSubscriberInterface
622
+ class BlogPostPublishSubscriber implements EventSubscriberInterface
610
623
{
611
624
public function guardPublish(GuardEvent $event)
612
625
{
@@ -809,10 +822,13 @@ requires:
809
822
810
823
Then you can access this metadata in your controller as follows::
811
824
825
+ // src/App/Controller/BlogPostController.php
826
+
812
827
use App\Entity\BlogPost;
813
828
use Symfony\Component\Workflow\Registry;
829
+ // ...
814
830
815
- public function myController (Registry $registry, BlogPost $post)
831
+ public function myAction (Registry $registry, BlogPost $post)
816
832
{
817
833
$workflow = $registry->get($post);
818
834
@@ -831,6 +847,8 @@ Then you can access this metadata in your controller as follows::
831
847
->getMetadataStore()
832
848
->getTransitionMetadata($aTransition)['priority'] ?? 0
833
849
;
850
+
851
+ // ...
834
852
}
835
853
836
854
There is a ``getMetadata() `` method that works with all kinds of metadata::
@@ -880,7 +898,7 @@ In Twig templates, metadata is available via the ``workflow_metadata()`` functio
880
898
{% for transition in workflow_transitions(blog_post) %}
881
899
<li>
882
900
{{ transition.name }}:
883
- <code>{{ workflow_metadata(blog_post, 'priority', transition) ?: '0' }}</code>
901
+ <code>{{ workflow_metadata(blog_post, 'priority', transition) ?: 0 }}</code>
884
902
</li>
885
903
{% endfor %}
886
904
</ul>
0 commit comments