@@ -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)
@@ -356,11 +359,14 @@ order:
356
359
Here is an example of how to enable logging for every time a "blog_publishing"
357
360
workflow leaves a place::
358
361
362
+ // src/App/EventSubscriber/WorkflowLoggerSubscriber.php
363
+ namespace App\EventSubscriber;
364
+
359
365
use Psr\Log\LoggerInterface;
360
366
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
361
367
use Symfony\Component\Workflow\Event\Event;
362
368
363
- class WorkflowLogger implements EventSubscriberInterface
369
+ class WorkflowLoggerSubscriber implements EventSubscriberInterface
364
370
{
365
371
private $logger;
366
372
@@ -406,14 +412,18 @@ list of the guard event names.
406
412
This example stops any blog post being transitioned to "reviewed" if it is
407
413
missing a title::
408
414
415
+ // src/App/EventSubscriber/BlogPostReviewSubscriber.php
416
+ namespace App\EventSubscriber;
417
+
418
+ use App\Entity\BlogPost;
409
419
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
410
420
use Symfony\Component\Workflow\Event\GuardEvent;
411
421
412
- class BlogPostReviewListener implements EventSubscriberInterface
422
+ class BlogPostReviewSubscriber implements EventSubscriberInterface
413
423
{
414
424
public function guardReview(GuardEvent $event)
415
425
{
416
- /** @var App\Entity\ BlogPost $post */
426
+ /** @var BlogPost $post */
417
427
$post = $event->getSubject();
418
428
$title = $post->title;
419
429
@@ -595,13 +605,14 @@ This example has been simplified; in production you may prefer to use the
595
605
:doc: `Translation </translation >` component to manage messages in one
596
606
place::
597
607
598
- namespace App\Listener\Workflow\Task;
608
+ // src/App/EventSubscriber/BlogPostPublishSubscriber.php
609
+ namespace App\EventSubscriber;
599
610
600
611
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
601
612
use Symfony\Component\Workflow\Event\GuardEvent;
602
613
use Symfony\Component\Workflow\TransitionBlocker;
603
614
604
- class BlogPostPublishListener implements EventSubscriberInterface
615
+ class BlogPostPublishSubscriber implements EventSubscriberInterface
605
616
{
606
617
public function guardPublish(GuardEvent $event)
607
618
{
@@ -796,10 +807,12 @@ requires:
796
807
797
808
Then you can access this metadata in your controller as follows::
798
809
810
+ // src/App/Controller/BlogPostController.php
799
811
use App\Entity\BlogPost;
800
812
use Symfony\Component\Workflow\Registry;
813
+ // ...
801
814
802
- public function myController (Registry $registry, BlogPost $post)
815
+ public function myAction (Registry $registry, BlogPost $post)
803
816
{
804
817
$workflow = $registry->get($post);
805
818
@@ -818,6 +831,8 @@ Then you can access this metadata in your controller as follows::
818
831
->getMetadataStore()
819
832
->getTransitionMetadata($aTransition)['priority'] ?? 0
820
833
;
834
+
835
+ // ...
821
836
}
822
837
823
838
There 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
867
882
{% for transition in workflow_transitions(blog_post) %}
868
883
<li>
869
884
{{ transition.name }}:
870
- <code>{{ workflow_metadata(blog_post, 'priority', transition) ?: '0' }}</code>
885
+ <code>{{ workflow_metadata(blog_post, 'priority', transition) ?: 0 }}</code>
871
886
</li>
872
887
{% endfor %}
873
888
</ul>
0 commit comments