Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 905119b

Browse filesBrowse files
feature #29145 [Workflow] Trigger entered event for subject entering in the Workflow for the first time (lyrixx)
This PR was merged into the 4.3-dev branch. Discussion ---------- [Workflow] Trigger `entered` event for subject entering in the Workflow for the first time | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #28319 | License | MIT | Doc PR | Commits ------- 388840f [Workflow] Trigger `entered` event for subject entering in the Workflow for the first time
2 parents a928d2b + 388840f commit 905119b
Copy full SHA for 905119b

File tree

Expand file treeCollapse file tree

4 files changed

+15
-4
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+15
-4
lines changed

‎src/Symfony/Component/Workflow/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.3.0
5+
-----
6+
7+
* Trigger `entered` event for subject entering in the Workflow for the first time
8+
49
4.1.0
510
-----
611

‎src/Symfony/Component/Workflow/Event/Event.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Event/Event.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Event extends BaseEvent
3535
* @param Transition $transition
3636
* @param WorkflowInterface $workflow
3737
*/
38-
public function __construct($subject, Marking $marking, Transition $transition, $workflow = null)
38+
public function __construct($subject, Marking $marking, Transition $transition = null, $workflow = null)
3939
{
4040
$this->subject = $subject;
4141
$this->marking = $marking;

‎src/Symfony/Component/Workflow/Tests/WorkflowTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Tests/WorkflowTest.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ public function testApplyWithEventDispatcher()
399399
$workflow = new Workflow($definition, new MultipleStateMarkingStore(), $eventDispatcher, 'workflow_name');
400400

401401
$eventNameExpected = array(
402+
'workflow.entered',
403+
'workflow.workflow_name.entered',
402404
'workflow.guard',
403405
'workflow.workflow_name.guard',
404406
'workflow.workflow_name.guard.t1',

‎src/Symfony/Component/Workflow/Workflow.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Workflow.php
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public function getMarking($subject)
6161

6262
// update the subject with the new marking
6363
$this->markingStore->setMarking($subject, $marking);
64+
65+
$this->entered($subject, null, $marking);
6466
}
6567

6668
// check that the subject has a known place
@@ -331,7 +333,7 @@ private function enter($subject, Transition $transition, Marking $marking): void
331333
}
332334
}
333335

334-
private function entered($subject, Transition $transition, Marking $marking): void
336+
private function entered($subject, Transition $transition = null, Marking $marking): void
335337
{
336338
if (null === $this->dispatcher) {
337339
return;
@@ -342,8 +344,10 @@ private function entered($subject, Transition $transition, Marking $marking): vo
342344
$this->dispatcher->dispatch('workflow.entered', $event);
343345
$this->dispatcher->dispatch(sprintf('workflow.%s.entered', $this->name), $event);
344346

345-
foreach ($transition->getTos() as $place) {
346-
$this->dispatcher->dispatch(sprintf('workflow.%s.entered.%s', $this->name, $place), $event);
347+
if ($transition) {
348+
foreach ($transition->getTos() as $place) {
349+
$this->dispatcher->dispatch(sprintf('workflow.%s.entered.%s', $this->name, $place), $event);
350+
}
347351
}
348352
}
349353

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.