Skip to content

Commit

Permalink
feature #30908 [Workflow] Added workflow_transition_blockers twig fun…
Browse files Browse the repository at this point in the history
…ction (lyrixx)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[Workflow] Added workflow_transition_blockers twig function

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | symfony/symfony-docs#11268
| License       | MIT
| Doc PR        | symfony/symfony-docs#11268

EUFOSSA

---

also related to #26689

I'm not a big fan of the current name. What should I pick?

cc @javiereguiluz

Commits
-------

a2f9975 [Workflow] Added workflow_transition_blockers twig function
  • Loading branch information
fabpot committed Apr 6, 2019
2 parents 4c78e60 + a2f9975 commit e5f14b7
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 e5f14b7

Please sign in to comment.