@@ -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)
@@ -364,11 +367,14 @@ order:
364
367
Here is an example of how to enable logging for every time a "blog_publishing"
365
368
workflow leaves a place::
366
369
370
+ // src/App/EventSubscriber/WorkflowLoggerSubscriber.php
371
+ namespace App\EventSubscriber;
372
+
367
373
use Psr\Log\LoggerInterface;
368
374
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
369
375
use Symfony\Component\Workflow\Event\Event;
370
376
371
- class WorkflowLogger implements EventSubscriberInterface
377
+ class WorkflowLoggerSubscriber implements EventSubscriberInterface
372
378
{
373
379
private $logger;
374
380
@@ -414,14 +420,18 @@ list of the guard event names.
414
420
This example stops any blog post being transitioned to "reviewed" if it is
415
421
missing a title::
416
422
423
+ // src/App/EventSubscriber/BlogPostReviewSubscriber.php
424
+ namespace App\EventSubscriber;
425
+
426
+ use App\Entity\BlogPost;
417
427
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
418
428
use Symfony\Component\Workflow\Event\GuardEvent;
419
429
420
- class BlogPostReviewListener implements EventSubscriberInterface
430
+ class BlogPostReviewSubscriber implements EventSubscriberInterface
421
431
{
422
432
public function guardReview(GuardEvent $event)
423
433
{
424
- /** @var App\Entity\ BlogPost $post */
434
+ /** @var BlogPost $post */
425
435
$post = $event->getSubject();
426
436
$title = $post->title;
427
437
@@ -606,13 +616,14 @@ This example has been simplified; in production you may prefer to use the
606
616
:doc: `Translation </translation >` component to manage messages in one
607
617
place::
608
618
609
- namespace App\Listener\Workflow\Task;
619
+ // src/App/EventSubscriber/BlogPostPublishSubscriber.php
620
+ namespace App\EventSubscriber;
610
621
611
622
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
612
623
use Symfony\Component\Workflow\Event\GuardEvent;
613
624
use Symfony\Component\Workflow\TransitionBlocker;
614
625
615
- class BlogPostPublishListener implements EventSubscriberInterface
626
+ class BlogPostPublishSubscriber implements EventSubscriberInterface
616
627
{
617
628
public function guardPublish(GuardEvent $event)
618
629
{
@@ -807,10 +818,12 @@ requires:
807
818
808
819
Then you can access this metadata in your controller as follows::
809
820
821
+ // src/App/Controller/BlogPostController.php
810
822
use App\Entity\BlogPost;
811
823
use Symfony\Component\Workflow\Registry;
824
+ // ...
812
825
813
- public function myController (Registry $registry, BlogPost $post)
826
+ public function myAction (Registry $registry, BlogPost $post)
814
827
{
815
828
$workflow = $registry->get($post);
816
829
@@ -829,6 +842,8 @@ Then you can access this metadata in your controller as follows::
829
842
->getMetadataStore()
830
843
->getTransitionMetadata($aTransition)['priority'] ?? 0
831
844
;
845
+
846
+ // ...
832
847
}
833
848
834
849
There 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
878
893
{% for transition in workflow_transitions(blog_post) %}
879
894
<li>
880
895
{{ transition.name }}:
881
- <code>{{ workflow_metadata(blog_post, 'priority', transition) ?: '0' }}</code>
896
+ <code>{{ workflow_metadata(blog_post, 'priority', transition) ?: 0 }}</code>
882
897
</li>
883
898
{% endfor %}
884
899
</ul>
0 commit comments