Skip to content

Commit 237468e

Browse files
committed
Tweaks and rewords
1 parent 1c69e79 commit 237468e

File tree

1 file changed

+21
-69
lines changed

1 file changed

+21
-69
lines changed

workflow.rst

Lines changed: 21 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -451,19 +451,9 @@ Choosing which Events to Dispatch
451451

452452
Ability to choose which events to dispatch was introduced in Symfony 5.2.
453453

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:
467457

468458
.. configuration-block::
469459

@@ -473,8 +463,12 @@ Valid options for ``events_to_dispatch`` are:
473463
framework:
474464
workflows:
475465
blog_publishing:
476-
# ...
466+
# you can pass one or more event names
477467
events_to_dispatch: ['workflow.leave', 'workflow.completed']
468+
469+
# pass an empty array to not dispatch any event
470+
events_to_dispatch: []
471+
478472
# ...
479473
480474
.. code-block:: xml
@@ -489,9 +483,13 @@ Valid options for ``events_to_dispatch`` are:
489483
>
490484
<framework:config>
491485
<framework:workflow name="blog_publishing">
492-
<!-- ... -->
486+
<!-- you can pass one or more event names -->
493487
<framework:event-to-dispatch>workflow.leave</framework:event-to-dispatch>
494488
<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+
495493
<!-- ... -->
496494
</framework:workflow>
497495
</framework:config>
@@ -504,67 +502,21 @@ Valid options for ``events_to_dispatch`` are:
504502
// ...
505503
'workflows' => [
506504
'blog_publishing' => [
507-
// ...
505+
// you can pass one or more event names
508506
'events_to_dispatch' => [
509507
'workflow.leave',
510508
'workflow.completed',
511509
],
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
553510
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
560512
'events_to_dispatch' => [],
513+
561514
// ...
562515
],
563516
],
564517
]);
565518
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::
568520

569521
use App\Entity\BlogPost;
570522
use Symfony\Component\Workflow\Exception\LogicException;
@@ -582,10 +534,10 @@ when applying a transition::
582534
// ...
583535
}
584536

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.
589541

590542
.. versionadded:: 5.1
591543

0 commit comments

Comments
 (0)