feature #30908 [Workflow] Added workflow_transition_blockers twig function (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 | https://github.com/symfony/symfony-docs/pull/11268
| License       | MIT
| Doc PR        | https://github.com/symfony/symfony-docs/pull/11268

EUFOSSA

---

also related to https://github.com/symfony/symfony/issues/26689

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

cc @javiereguiluz

Commits
-------

a2f99757f1 [Workflow] Added workflow_transition_blockers twig function
This commit is contained in:
Fabien Potencier 2019-04-06 20:23:30 +02:00
commit e5f14b7d28
3 changed files with 23 additions and 0 deletions

View File

@ -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
-----

View File

@ -13,6 +13,7 @@ namespace Symfony\Bridge\Twig\Extension;
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 @@ class WorkflowExtension extends AbstractExtension
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 @@ class WorkflowExtension extends AbstractExtension
;
}
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';

View File

@ -20,6 +20,7 @@ use Symfony\Component\Workflow\Registry;
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 @@ class WorkflowExtensionTest extends TestCase
$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