bug #23299 [Workflow] Added more events to the announce function (Nyholm)

This PR was submitted for the master branch but it was merged into the 3.2 branch instead (closes #23299).

Discussion
----------

[Workflow] Added more events to the announce function

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | yes/no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23275
| License       | MIT
| Doc PR        | #8087

This PR will fix #23275

The documentation states that we dispatch events `workflow.announce` and `workflow.[name].announce`. It was me who wrongly added it to the docs... sorry about that.

We could either: Change the docs or add these events. I choose to add these event to the source since the same events are dispatched for "guard", "leave", "transition", "enter" and "entered".

Commits
-------

c5042f35e1 [Workflow] Added more events to the announce function
This commit is contained in:
Grégoire Pineau 2017-06-26 14:40:45 +02:00
commit 25ab3390d3
2 changed files with 5 additions and 0 deletions

View File

@ -259,6 +259,8 @@ class WorkflowTest extends TestCase
'workflow.workflow_name.enter.b',
'workflow.workflow_name.enter.c',
// Following events are fired because of announce() method
'workflow.announce',
'workflow.workflow_name.announce',
'workflow.guard',
'workflow.workflow_name.guard',
'workflow.workflow_name.guard.t2',

View File

@ -282,6 +282,9 @@ class Workflow
$event = new Event($subject, $marking, $initialTransition);
$this->dispatcher->dispatch('workflow.announce', $event);
$this->dispatcher->dispatch(sprintf('workflow.%s.announce', $this->name), $event);
foreach ($this->getEnabledTransitions($subject) as $transition) {
$this->dispatcher->dispatch(sprintf('workflow.%s.announce.%s', $this->name, $transition->getName()), $event);
}