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 0eebe74

Browse filesBrowse files
epitrefabpot
authored andcommitted
[Workflow] Added Function (and Twig extension) to retrieve a specific transition
1 parent 80d1f44 commit 0eebe74
Copy full SHA for 0eebe74

File tree

7 files changed

+64
-4
lines changed
Filter options

7 files changed

+64
-4
lines changed

‎src/Symfony/Bridge/Twig/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/CHANGELOG.md
+7-2Lines changed: 7 additions & 2 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 `workflow_transition` to easily retrieve a specific transition object
8+
49
5.0.0
510
-----
611

@@ -16,7 +21,7 @@ CHANGELOG
1621

1722
* added a new `TwigErrorRenderer` for `html` format, integrated with the `ErrorHandler` component
1823
* marked all classes extending twig as `@final`
19-
* deprecated to pass `$rootDir` and `$fileLinkFormatter` as 5th and 6th argument respectively to the
24+
* deprecated to pass `$rootDir` and `$fileLinkFormatter` as 5th and 6th argument respectively to the
2025
`DebugCommand::__construct()` method, swap the variables position.
2126
* the `LintCommand` lints all the templates stored in all configured Twig paths if none argument is provided
2227
* deprecated accepting STDIN implicitly when using the `lint:twig` command, use `lint:twig -` (append a dash) instead to make it explicit.
@@ -29,7 +34,7 @@ CHANGELOG
2934

3035
* added the `form_parent()` function that allows to reliably retrieve the parent form in Twig templates
3136
* added the `workflow_transition_blockers()` function
32-
* deprecated the `$requestStack` and `$requestContext` arguments of the
37+
* deprecated the `$requestStack` and `$requestContext` arguments of the
3338
`HttpFoundationExtension`, pass a `Symfony\Component\HttpFoundation\UrlHelper`
3439
instance as the only argument instead
3540

‎src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function getFunctions(): array
3939
return [
4040
new TwigFunction('workflow_can', [$this, 'canTransition']),
4141
new TwigFunction('workflow_transitions', [$this, 'getEnabledTransitions']),
42+
new TwigFunction('workflow_transition', [$this, 'getEnabledTransition']),
4243
new TwigFunction('workflow_has_marked_place', [$this, 'hasMarkedPlace']),
4344
new TwigFunction('workflow_marked_places', [$this, 'getMarkedPlaces']),
4445
new TwigFunction('workflow_metadata', [$this, 'getMetadata']),
@@ -64,6 +65,11 @@ public function getEnabledTransitions(object $subject, string $name = null): arr
6465
return $this->workflowRegistry->get($subject, $name)->getEnabledTransitions($subject);
6566
}
6667

68+
public function getEnabledTransition(object $subject, string $transition, string $name = null): ?Transition
69+
{
70+
return $this->workflowRegistry->get($subject, $name)->getEnabledTransition($subject, $transition);
71+
}
72+
6773
/**
6874
* Returns true if the place is marked.
6975
*/

‎src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ public function testGetEnabledTransitions()
8181
$this->assertSame('t1', $transitions[0]->getName());
8282
}
8383

84+
public function testGetEnabledTransition()
85+
{
86+
$subject = new Subject();
87+
88+
$transition = $this->extension->getEnabledTransition($subject, 't1');
89+
90+
$this->assertInstanceOf(Transition::class, $transition);
91+
$this->assertSame('t1', $transition->getName());
92+
}
93+
8494
public function testHasMarkedPlace()
8595
{
8696
$subject = new Subject(['ordered' => 1, 'waiting_for_payment' => 1]);

‎src/Symfony/Bridge/Twig/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/composer.json
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"symfony/console": "^4.4|^5.0",
4343
"symfony/expression-language": "^4.4|^5.0",
4444
"symfony/web-link": "^4.4|^5.0",
45-
"symfony/workflow": "^4.4|^5.0",
45+
"symfony/workflow": "^5.2",
4646
"twig/cssinliner-extra": "^2.12",
4747
"twig/inky-extra": "^2.12",
4848
"twig/markdown-extra": "^2.12"
@@ -53,7 +53,7 @@
5353
"symfony/http-foundation": "<4.4",
5454
"symfony/http-kernel": "<4.4",
5555
"symfony/translation": "<5.0",
56-
"symfony/workflow": "<4.4"
56+
"symfony/workflow": "<5.2"
5757
},
5858
"suggest": {
5959
"symfony/finder": "",

‎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+
5.2.0
5+
-----
6+
7+
* Added function `getEnabledTransition` to easily retrieve a specific transition object
8+
49
5.1.0
510
-----
611

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/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();

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/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.