Skip to content

Commit

Permalink
[Workflow] Added workflow_transition_blockers twig function
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrixx committed Apr 6, 2019
1 parent ede6660 commit a2f9975
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Symfony/Bridge/Twig/CHANGELOG.md
Expand Up @@ -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
-----
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php
Expand Up @@ -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;

Expand All @@ -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']),
];
}

Expand Down Expand Up @@ -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';
Expand Down
13 changes: 13 additions & 0 deletions src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a2f9975

Please sign in to comment.