@@ -451,19 +451,9 @@ Choosing which Events to Dispatch
451
451
452
452
Ability to choose which events to dispatch was introduced in Symfony 5.2.
453
453
454
- You are able to specify which events (does not apply to Guard event) will be
455
- fired when performing each transition by passing an array of workflow events
456
- to the ``events_to_dispatch `` configuration option.
457
-
458
- Valid options for ``events_to_dispatch `` are:
459
-
460
- * ``null `` - all events are dispatched
461
- * ``[] `` - no events are dispatched
462
- * ``['workflow.leave', 'workflow.completed'] `` - only specific events are dispatched
463
-
464
- .. note ::
465
-
466
- Guard Events are still dispatched in all instances.
454
+ If you prefer to control which events are fired when performing each transition,
455
+ use the ``events_to_dispatch `` configuration option. This option does not apply
456
+ to :ref: `Guard events <workflow-usage-guard-events >`, which are always fired:
467
457
468
458
.. configuration-block ::
469
459
@@ -473,8 +463,12 @@ Valid options for ``events_to_dispatch`` are:
473
463
framework :
474
464
workflows :
475
465
blog_publishing :
476
- # ...
466
+ # you can pass one or more event names
477
467
events_to_dispatch : ['workflow.leave', 'workflow.completed']
468
+
469
+ # pass an empty array to not dispatch any event
470
+ events_to_dispatch : []
471
+
478
472
# ...
479
473
480
474
.. code-block :: xml
@@ -489,9 +483,13 @@ Valid options for ``events_to_dispatch`` are:
489
483
>
490
484
<framework : config >
491
485
<framework : workflow name =" blog_publishing" >
492
- <!-- ... -->
486
+ <!-- you can pass one or more event names -->
493
487
<framework : event-to-dispatch >workflow.leave</framework : event-to-dispatch >
494
488
<framework : event-to-dispatch >workflow.completed</framework : event-to-dispatch >
489
+
490
+ <!-- pass an empty array to not dispatch any event -->
491
+ <framework : event-to-dispatch ></framework : event-to-dispatch >
492
+
495
493
<!-- ... -->
496
494
</framework : workflow >
497
495
</framework : config >
@@ -504,67 +502,21 @@ Valid options for ``events_to_dispatch`` are:
504
502
// ...
505
503
'workflows' => [
506
504
'blog_publishing' => [
507
- // ...
505
+ // you can pass one or more event names
508
506
'events_to_dispatch' => [
509
507
'workflow.leave',
510
508
'workflow.completed',
511
509
],
512
- // ...
513
- ],
514
- ],
515
- ]);
516
-
517
- To specify that no events will be dispatched pass an empty array to the
518
- configuration option.
519
-
520
- .. configuration-block ::
521
-
522
- .. code-block :: yaml
523
-
524
- # config/packages/workflow.yaml
525
- framework :
526
- workflows :
527
- blog_publishing :
528
- # ...
529
- events_to_dispatch : []
530
- # ...
531
-
532
- .. code-block :: xml
533
-
534
- <!-- config/packages/workflow.xml -->
535
- <?xml version =" 1.0" encoding =" UTF-8" ?>
536
- <container xmlns =" http://symfony.com/schema/dic/services"
537
- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
538
- xmlns : framework =" http://symfony.com/schema/dic/symfony"
539
- xsi : schemaLocation =" http://symfony.com/schema/dic/services
540
- https://symfony.com/schema/dic/services/services-1.0.xsd
541
- http://symfony.com/schema/dic/symfony
542
- https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
543
- <framework : config >
544
- <framework : workflow name =" blog_publishing" >
545
- <!-- ... -->
546
- <framework : event-to-dispatch ></framework : event-to-dispatch >
547
- <!-- ... -->
548
- </framework : workflow >
549
- </framework : config >
550
- </container >
551
-
552
- .. code-block :: php
553
510
554
- // config/packages/workflow.php
555
- $container->loadFromExtension('framework', [
556
- // ...
557
- 'workflows' => [
558
- 'blog_publishing' => [
559
- // ...
511
+ // pass an empty array to not dispatch any event
560
512
'events_to_dispatch' => [],
513
+
561
514
// ...
562
515
],
563
516
],
564
517
]);
565
518
566
- You are also able to explicitly disable a specific event from being fired
567
- when applying a transition::
519
+ You can also disable a specific event from being fired when applying a transition::
568
520
569
521
use App\Entity\BlogPost;
570
522
use Symfony\Component\Workflow\Exception\LogicException;
@@ -582,10 +534,10 @@ when applying a transition::
582
534
// ...
583
535
}
584
536
585
- Choosing to disable an event for a specific transition will take precedence
586
- over any events specified in the workflow configuration. In the above example
587
- the ``workflow.leave `` event will not be fired, even if it has been specified
588
- as an event to be dispatched for all transitions in the workflow configuration.
537
+ Disabling an event for a specific transition will take precedence over any
538
+ events specified in the workflow configuration. In the above example the
539
+ ``workflow.leave `` event will not be fired, even if it has been specified as an
540
+ event to be dispatched for all transitions in the workflow configuration.
589
541
590
542
.. versionadded :: 5.1
591
543
0 commit comments