@@ -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)
@@ -356,11 +359,14 @@ order:
356359Here is an example of how to enable logging for every time a "blog_publishing"
357360workflow leaves a place::
358361
362+ // src/App/EventSubscriber/WorkflowLoggerSubscriber.php
363+ namespace App\EventSubscriber;
364+
359365 use Psr\Log\LoggerInterface;
360366 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
361367 use Symfony\Component\Workflow\Event\Event;
362368
363- class WorkflowLogger implements EventSubscriberInterface
369+ class WorkflowLoggerSubscriber implements EventSubscriberInterface
364370 {
365371 private $logger;
366372
@@ -406,14 +412,18 @@ list of the guard event names.
406412This example stops any blog post being transitioned to "reviewed" if it is
407413missing a title::
408414
415+ // src/App/EventSubscriber/BlogPostReviewSubscriber.php
416+ namespace App\EventSubscriber;
417+
418+ use App\Entity\BlogPost;
409419 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
410420 use Symfony\Component\Workflow\Event\GuardEvent;
411421
412- class BlogPostReviewListener implements EventSubscriberInterface
422+ class BlogPostReviewSubscriber implements EventSubscriberInterface
413423 {
414424 public function guardReview(GuardEvent $event)
415425 {
416- /** @var App\Entity\ BlogPost $post */
426+ /** @var BlogPost $post */
417427 $post = $event->getSubject();
418428 $title = $post->title;
419429
@@ -595,13 +605,14 @@ This example has been simplified; in production you may prefer to use the
595605:doc: `Translation </translation >` component to manage messages in one
596606place::
597607
598- namespace App\Listener\Workflow\Task;
608+ // src/App/EventSubscriber/BlogPostPublishSubscriber.php
609+ namespace App\EventSubscriber;
599610
600611 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
601612 use Symfony\Component\Workflow\Event\GuardEvent;
602613 use Symfony\Component\Workflow\TransitionBlocker;
603614
604- class BlogPostPublishListener implements EventSubscriberInterface
615+ class BlogPostPublishSubscriber implements EventSubscriberInterface
605616 {
606617 public function guardPublish(GuardEvent $event)
607618 {
@@ -796,10 +807,12 @@ requires:
796807
797808 Then you can access this metadata in your controller as follows::
798809
810+ // src/App/Controller/BlogPostController.php
799811 use App\Entity\BlogPost;
800812 use Symfony\Component\Workflow\Registry;
813+ // ...
801814
802- public function myController (Registry $registry, BlogPost $post)
815+ public function myAction (Registry $registry, BlogPost $post)
803816 {
804817 $workflow = $registry->get($post);
805818
@@ -818,6 +831,8 @@ Then you can access this metadata in your controller as follows::
818831 ->getMetadataStore()
819832 ->getTransitionMetadata($aTransition)['priority'] ?? 0
820833 ;
834+
835+ // ...
821836 }
822837
823838There is a ``getMetadata() `` method that works with all kinds of metadata::
@@ -867,7 +882,7 @@ In Twig templates, metadata is available via the ``workflow_metadata()`` functio
867882 {% for transition in workflow_transitions(blog_post) %}
868883 <li>
869884 {{ transition.name }}:
870- <code>{{ workflow_metadata(blog_post, 'priority', transition) ?: '0' }}</code>
885+ <code>{{ workflow_metadata(blog_post, 'priority', transition) ?: 0 }}</code>
871886 </li>
872887 {% endfor %}
873888 </ul>
0 commit comments