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 a2f9975

Browse filesBrowse files
committed
[Workflow] Added workflow_transition_blockers twig function
1 parent ede6660 commit a2f9975
Copy full SHA for a2f9975

File tree

3 files changed

+23
-0
lines changed
Filter options

3 files changed

+23
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* added the `form_parent()` function that allows to reliably retrieve the parent form in Twig templates
8+
* added the `workflow_transition_blockers()` function
89

910
4.2.0
1011
-----

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Workflow\Registry;
1515
use Symfony\Component\Workflow\Transition;
16+
use Symfony\Component\Workflow\TransitionBlockerList;
1617
use Twig\Extension\AbstractExtension;
1718
use Twig\TwigFunction;
1819

@@ -38,6 +39,7 @@ public function getFunctions()
3839
new TwigFunction('workflow_has_marked_place', [$this, 'hasMarkedPlace']),
3940
new TwigFunction('workflow_marked_places', [$this, 'getMarkedPlaces']),
4041
new TwigFunction('workflow_metadata', [$this, 'getMetadata']),
42+
new TwigFunction('workflow_transition_blockers', [$this, 'buildTransitionBlockerList']),
4143
];
4244
}
4345

@@ -120,6 +122,13 @@ public function getMetadata($subject, string $key, $metadataSubject = null, stri
120122
;
121123
}
122124

125+
public function buildTransitionBlockerList($subject, string $transitionName, string $name = null): TransitionBlockerList
126+
{
127+
$workflow = $this->workflowRegistry->get($subject, $name);
128+
129+
return $workflow->buildTransitionBlockerList($subject, $transitionName);
130+
}
131+
123132
public function getName()
124133
{
125134
return 'workflow';

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\Workflow\SupportStrategy\ClassInstanceSupportStrategy;
2121
use Symfony\Component\Workflow\SupportStrategy\InstanceOfSupportStrategy;
2222
use Symfony\Component\Workflow\Transition;
23+
use Symfony\Component\Workflow\TransitionBlockerList;
2324
use Symfony\Component\Workflow\Workflow;
2425

2526
class WorkflowExtensionTest extends TestCase
@@ -110,6 +111,18 @@ public function testGetMetadata()
110111
$this->assertNull($this->extension->getMetadata($subject, 'not found'));
111112
$this->assertNull($this->extension->getMetadata($subject, 'not found', $this->t1));
112113
}
114+
115+
public function testbuildTransitionBlockerList()
116+
{
117+
if (!class_exists(TransitionBlockerList::class)) {
118+
$this->markTestSkipped('This test requires symfony/workflow:4.1.');
119+
}
120+
$subject = new Subject();
121+
122+
$list = $this->extension->buildTransitionBlockerList($subject, 't1');
123+
$this->assertInstanceOf(TransitionBlockerList::class, $list);
124+
$this->assertTrue($list->isEmpty());
125+
}
113126
}
114127

115128
final class Subject

0 commit comments

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