From a2f99757f1fa338e982deecc9ec6dc2b6922eb44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Sat, 6 Apr 2019 16:34:59 +0200 Subject: [PATCH] [Workflow] Added workflow_transition_blockers twig function --- src/Symfony/Bridge/Twig/CHANGELOG.md | 1 + .../Bridge/Twig/Extension/WorkflowExtension.php | 9 +++++++++ .../Twig/Tests/Extension/WorkflowExtensionTest.php | 13 +++++++++++++ 3 files changed, 23 insertions(+) diff --git a/src/Symfony/Bridge/Twig/CHANGELOG.md b/src/Symfony/Bridge/Twig/CHANGELOG.md index 35752fff125a..3b806c47fb2b 100644 --- a/src/Symfony/Bridge/Twig/CHANGELOG.md +++ b/src/Symfony/Bridge/Twig/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG ----- * added the `form_parent()` function that allows to reliably retrieve the parent form in Twig templates + * added the `workflow_transition_blockers()` function 4.2.0 ----- diff --git a/src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php b/src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php index 05c236a1648d..85b4f7a4d73c 100644 --- a/src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php @@ -13,6 +13,7 @@ use Symfony\Component\Workflow\Registry; use Symfony\Component\Workflow\Transition; +use Symfony\Component\Workflow\TransitionBlockerList; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; @@ -38,6 +39,7 @@ public function getFunctions() new TwigFunction('workflow_has_marked_place', [$this, 'hasMarkedPlace']), new TwigFunction('workflow_marked_places', [$this, 'getMarkedPlaces']), new TwigFunction('workflow_metadata', [$this, 'getMetadata']), + new TwigFunction('workflow_transition_blockers', [$this, 'buildTransitionBlockerList']), ]; } @@ -120,6 +122,13 @@ public function getMetadata($subject, string $key, $metadataSubject = null, stri ; } + public function buildTransitionBlockerList($subject, string $transitionName, string $name = null): TransitionBlockerList + { + $workflow = $this->workflowRegistry->get($subject, $name); + + return $workflow->buildTransitionBlockerList($subject, $transitionName); + } + public function getName() { return 'workflow'; diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php index 32f4e82dad1c..3e948bae3f50 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php @@ -20,6 +20,7 @@ use Symfony\Component\Workflow\SupportStrategy\ClassInstanceSupportStrategy; use Symfony\Component\Workflow\SupportStrategy\InstanceOfSupportStrategy; use Symfony\Component\Workflow\Transition; +use Symfony\Component\Workflow\TransitionBlockerList; use Symfony\Component\Workflow\Workflow; class WorkflowExtensionTest extends TestCase @@ -110,6 +111,18 @@ public function testGetMetadata() $this->assertNull($this->extension->getMetadata($subject, 'not found')); $this->assertNull($this->extension->getMetadata($subject, 'not found', $this->t1)); } + + public function testbuildTransitionBlockerList() + { + if (!class_exists(TransitionBlockerList::class)) { + $this->markTestSkipped('This test requires symfony/workflow:4.1.'); + } + $subject = new Subject(); + + $list = $this->extension->buildTransitionBlockerList($subject, 't1'); + $this->assertInstanceOf(TransitionBlockerList::class, $list); + $this->assertTrue($list->isEmpty()); + } } final class Subject