diff --git a/src/Symfony/Component/Workflow/CHANGELOG.md b/src/Symfony/Component/Workflow/CHANGELOG.md index 5d0f6a6abb241..4668f2f68af17 100644 --- a/src/Symfony/Component/Workflow/CHANGELOG.md +++ b/src/Symfony/Component/Workflow/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +4.3.0 +----- + + * Trigger `entered` event for subject entering in the Workflow for the first time + 4.1.0 ----- diff --git a/src/Symfony/Component/Workflow/Event/Event.php b/src/Symfony/Component/Workflow/Event/Event.php index 395f2fd97bfe1..79ba18d6a5306 100644 --- a/src/Symfony/Component/Workflow/Event/Event.php +++ b/src/Symfony/Component/Workflow/Event/Event.php @@ -35,7 +35,7 @@ class Event extends BaseEvent * @param Transition $transition * @param WorkflowInterface $workflow */ - public function __construct($subject, Marking $marking, Transition $transition, $workflow = null) + public function __construct($subject, Marking $marking, Transition $transition = null, $workflow = null) { $this->subject = $subject; $this->marking = $marking; diff --git a/src/Symfony/Component/Workflow/Tests/WorkflowTest.php b/src/Symfony/Component/Workflow/Tests/WorkflowTest.php index 87f48002487d7..e83162b74775f 100644 --- a/src/Symfony/Component/Workflow/Tests/WorkflowTest.php +++ b/src/Symfony/Component/Workflow/Tests/WorkflowTest.php @@ -373,6 +373,8 @@ public function testApplyWithEventDispatcher() $workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name'); $eventNameExpected = array( + 'workflow.entered', + 'workflow.workflow_name.entered', 'workflow.guard', 'workflow.workflow_name.guard', 'workflow.workflow_name.guard.t1', diff --git a/src/Symfony/Component/Workflow/Workflow.php b/src/Symfony/Component/Workflow/Workflow.php index 21676e0fc89ae..936c19f948148 100644 --- a/src/Symfony/Component/Workflow/Workflow.php +++ b/src/Symfony/Component/Workflow/Workflow.php @@ -61,6 +61,8 @@ public function getMarking($subject) // update the subject with the new marking $this->markingStore->setMarking($subject, $marking); + + $this->entered($subject, null, $marking); } // check that the subject has a known place @@ -323,7 +325,7 @@ private function enter($subject, Transition $transition, Marking $marking): void } } - private function entered($subject, Transition $transition, Marking $marking): void + private function entered($subject, Transition $transition = null, Marking $marking): void { if (null === $this->dispatcher) { return; @@ -334,8 +336,10 @@ private function entered($subject, Transition $transition, Marking $marking): vo $this->dispatcher->dispatch('workflow.entered', $event); $this->dispatcher->dispatch(sprintf('workflow.%s.entered', $this->name), $event); - foreach ($transition->getTos() as $place) { - $this->dispatcher->dispatch(sprintf('workflow.%s.entered.%s', $this->name, $place), $event); + if ($transition) { + foreach ($transition->getTos() as $place) { + $this->dispatcher->dispatch(sprintf('workflow.%s.entered.%s', $this->name, $place), $event); + } } }
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: