@@ -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)
@@ -364,11 +367,14 @@ order:
364367Here is an example of how to enable logging for every time a "blog_publishing"
365368workflow leaves a place::
366369
370+ // src/App/EventSubscriber/WorkflowLoggerSubscriber.php
371+ namespace App\EventSubscriber;
372+
367373 use Psr\Log\LoggerInterface;
368374 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
369375 use Symfony\Component\Workflow\Event\Event;
370376
371- class WorkflowLogger implements EventSubscriberInterface
377+ class WorkflowLoggerSubscriber implements EventSubscriberInterface
372378 {
373379 private $logger;
374380
@@ -414,14 +420,18 @@ list of the guard event names.
414420This example stops any blog post being transitioned to "reviewed" if it is
415421missing a title::
416422
423+ // src/App/EventSubscriber/BlogPostReviewSubscriber.php
424+ namespace App\EventSubscriber;
425+
426+ use App\Entity\BlogPost;
417427 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
418428 use Symfony\Component\Workflow\Event\GuardEvent;
419429
420- class BlogPostReviewListener implements EventSubscriberInterface
430+ class BlogPostReviewSubscriber implements EventSubscriberInterface
421431 {
422432 public function guardReview(GuardEvent $event)
423433 {
424- /** @var App\Entity\ BlogPost $post */
434+ /** @var BlogPost $post */
425435 $post = $event->getSubject();
426436 $title = $post->title;
427437
@@ -606,13 +616,14 @@ This example has been simplified; in production you may prefer to use the
606616:doc: `Translation </translation >` component to manage messages in one
607617place::
608618
609- namespace App\Listener\Workflow\Task;
619+ // src/App/EventSubscriber/BlogPostPublishSubscriber.php
620+ namespace App\EventSubscriber;
610621
611622 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
612623 use Symfony\Component\Workflow\Event\GuardEvent;
613624 use Symfony\Component\Workflow\TransitionBlocker;
614625
615- class BlogPostPublishListener implements EventSubscriberInterface
626+ class BlogPostPublishSubscriber implements EventSubscriberInterface
616627 {
617628 public function guardPublish(GuardEvent $event)
618629 {
@@ -807,10 +818,12 @@ requires:
807818
808819 Then you can access this metadata in your controller as follows::
809820
821+ // src/App/Controller/BlogPostController.php
810822 use App\Entity\BlogPost;
811823 use Symfony\Component\Workflow\Registry;
824+ // ...
812825
813- public function myController (Registry $registry, BlogPost $post)
826+ public function myAction (Registry $registry, BlogPost $post)
814827 {
815828 $workflow = $registry->get($post);
816829
@@ -829,6 +842,8 @@ Then you can access this metadata in your controller as follows::
829842 ->getMetadataStore()
830843 ->getTransitionMetadata($aTransition)['priority'] ?? 0
831844 ;
845+
846+ // ...
832847 }
833848
834849There is a ``getMetadata() `` method that works with all kinds of metadata::
@@ -878,7 +893,7 @@ In Twig templates, metadata is available via the ``workflow_metadata()`` functio
878893 {% for transition in workflow_transitions(blog_post) %}
879894 <li>
880895 {{ transition.name }}:
881- <code>{{ workflow_metadata(blog_post, 'priority', transition) ?: '0' }}</code>
896+ <code>{{ workflow_metadata(blog_post, 'priority', transition) ?: 0 }}</code>
882897 </li>
883898 {% endfor %}
884899 </ul>
0 commit comments