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 1c1dcef

Browse filesBrowse files
committed
feature #37428 [Workflow] Added Function (and Twig extension) to retrieve a specific transition (Carlos Pereira De Amorim)
This PR was squashed before being merged into the 5.2-dev branch. Discussion ---------- [Workflow] Added Function (and Twig extension) to retrieve a specific transition You can now easily retrieve a specific transition. Useful when you want the metadata of a specific transition. | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | hmmmm, should I create a ticket first ? | License | MIT | Doc PR | symfony/symfony-docs#13907 I needed to get the metadata of a transition, but in order to do that, you need the transition object. So here is a PR to easily get the transition object Commits ------- 0eebe74259 [Workflow] Added Function (and Twig extension) to retrieve a specific transition
2 parents 701eea5 + 184ae49 commit 1c1dcef
Copy full SHA for 1c1dcef

File tree

3 files changed

+39
-0
lines changed
Filter options

3 files changed

+39
-0
lines changed

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: 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+
5.2.0
5+
-----
6+
7+
* Added function `getEnabledTransition` to easily retrieve a specific transition object
8+
49
5.1.0
510
-----
611

‎Tests/WorkflowTest.php

Copy file name to clipboardExpand all lines: Tests/WorkflowTest.php
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,21 @@ public function testGetEnabledTransitions()
592592
$this->assertSame('t5', $transitions[0]->getName());
593593
}
594594

595+
public function testGetEnabledTransition()
596+
{
597+
$definition = $this->createComplexWorkflowDefinition();
598+
$subject = new Subject();
599+
$workflow = new Workflow($definition, new MethodMarkingStore());
600+
601+
$subject->setMarking(['d' => 1]);
602+
$transition = $workflow->getEnabledTransition($subject, 't3');
603+
$this->assertInstanceOf(Transition::class, $transition);
604+
$this->assertSame('t3', $transition->getName());
605+
606+
$transition = $workflow->getEnabledTransition($subject, 'does_not_exist');
607+
$this->assertNull($transition);
608+
}
609+
595610
public function testGetEnabledTransitionsWithSameNameTransition()
596611
{
597612
$definition = $this->createWorkflowWithSameNameTransition();

‎Workflow.php

Copy file name to clipboardExpand all lines: Workflow.php
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,25 @@ public function getEnabledTransitions(object $subject)
235235
return $enabledTransitions;
236236
}
237237

238+
public function getEnabledTransition(object $subject, string $name): ?Transition
239+
{
240+
$marking = $this->getMarking($subject);
241+
242+
foreach ($this->definition->getTransitions() as $transition) {
243+
if ($transition->getName() !== $name) {
244+
continue;
245+
}
246+
$transitionBlockerList = $this->buildTransitionBlockerListForTransition($subject, $marking, $transition);
247+
if (!$transitionBlockerList->isEmpty()) {
248+
continue;
249+
}
250+
251+
return $transition;
252+
}
253+
254+
return null;
255+
}
256+
238257
/**
239258
* {@inheritdoc}
240259
*/

0 commit comments

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