@@ -165,9 +165,12 @@ like this:
165165
166166The configured property will be used via it's implemented getter/setter methods by the marking store::
167167
168+ // src/Entity/BlogPost.php
169+ namespace App\Entity;
170+
168171 class BlogPost
169172 {
170- // the configured property must be declared
173+ // the configured marking store property must be declared
171174 private $currentPlace;
172175 private $title;
173176 private $content;
@@ -236,11 +239,11 @@ Accessing the Workflow in a Class
236239To access workflow inside a class, use dependency injection and inject the
237240registry in the constructor::
238241
242+ use App\Entity\BlogPost;
239243 use Symfony\Component\Workflow\Registry;
240244
241245 class MyClass
242246 {
243-
244247 private $workflowRegistry;
245248
246249 public function __construct(Registry $workflowRegistry)
@@ -361,11 +364,15 @@ order:
361364Here is an example of how to enable logging for every time a "blog_publishing"
362365workflow leaves a place::
363366
367+ // src/App/EventSubscriber/WorkflowLoggerSubscriber.php
368+
369+ namespace App\EventSubscriber;
370+
364371 use Psr\Log\LoggerInterface;
365372 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
366373 use Symfony\Component\Workflow\Event\Event;
367374
368- class WorkflowLogger implements EventSubscriberInterface
375+ class WorkflowLoggerSubscriber implements EventSubscriberInterface
369376 {
370377 private $logger;
371378
@@ -411,14 +418,19 @@ list of the guard event names.
411418This example stops any blog post being transitioned to "reviewed" if it is
412419missing a title::
413420
421+ // src/App/EventSubscriber/BlogPostReviewSubscriber.php
422+
423+ namespace App\EventSubscriber;
424+
425+ use App\Entity\BlogPost;
414426 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
415427 use Symfony\Component\Workflow\Event\GuardEvent;
416428
417- class BlogPostReviewListener implements EventSubscriberInterface
429+ class BlogPostReviewSubscriber implements EventSubscriberInterface
418430 {
419431 public function guardReview(GuardEvent $event)
420432 {
421- /** @var App\Entity\ BlogPost $post */
433+ /** @var BlogPost $post */
422434 $post = $event->getSubject();
423435 $title = $post->title;
424436
@@ -600,13 +612,14 @@ This example has been simplified; in production you may prefer to use the
600612:doc: `Translation </translation >` component to manage messages in one
601613place::
602614
603- namespace App\Listener\Workflow\Task;
615+ // src/App/EventSubscriber/BlogPostPublishSubscriber.php
616+ namespace App\EventSubscriber;
604617
605618 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
606619 use Symfony\Component\Workflow\Event\GuardEvent;
607620 use Symfony\Component\Workflow\TransitionBlocker;
608621
609- class BlogPostPublishListener implements EventSubscriberInterface
622+ class BlogPostPublishSubscriber implements EventSubscriberInterface
610623 {
611624 public function guardPublish(GuardEvent $event)
612625 {
@@ -809,10 +822,13 @@ requires:
809822
810823 Then you can access this metadata in your controller as follows::
811824
825+ // src/App/Controller/BlogPostController.php
826+
812827 use App\Entity\BlogPost;
813828 use Symfony\Component\Workflow\Registry;
829+ // ...
814830
815- public function myController (Registry $registry, BlogPost $post)
831+ public function myAction (Registry $registry, BlogPost $post)
816832 {
817833 $workflow = $registry->get($post);
818834
@@ -831,6 +847,8 @@ Then you can access this metadata in your controller as follows::
831847 ->getMetadataStore()
832848 ->getTransitionMetadata($aTransition)['priority'] ?? 0
833849 ;
850+
851+ // ...
834852 }
835853
836854There 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
880898 {% for transition in workflow_transitions(blog_post) %}
881899 <li>
882900 {{ transition.name }}:
883- <code>{{ workflow_metadata(blog_post, 'priority', transition) ?: '0' }}</code>
901+ <code>{{ workflow_metadata(blog_post, 'priority', transition) ?: 0 }}</code>
884902 </li>
885903 {% endfor %}
886904 </ul>
0 commit comments