Skip to content

Commit 9fddc83

Browse files
epitrefabpot
authored andcommitted
[Workflow] Added Function (and Twig extension) to retrieve a specific transition
1 parent 1d9d625 commit 9fddc83

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

CHANGELOG.md

Lines 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

Extension/WorkflowExtension.php

Lines 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
*/

Tests/Extension/WorkflowExtensionTest.php

Lines 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]);

composer.json

Lines 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": "",

0 commit comments

Comments
 (0)