[Workflow] Added workflow_transition_blockers twig function
This commit is contained in:
parent
ede66604d7
commit
a2f99757f1
@ -5,6 +5,7 @@ CHANGELOG
|
|||||||
-----
|
-----
|
||||||
|
|
||||||
* added the `form_parent()` function that allows to reliably retrieve the parent form in Twig templates
|
* 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
|
4.2.0
|
||||||
-----
|
-----
|
||||||
|
@ -13,6 +13,7 @@ namespace Symfony\Bridge\Twig\Extension;
|
|||||||
|
|
||||||
use Symfony\Component\Workflow\Registry;
|
use Symfony\Component\Workflow\Registry;
|
||||||
use Symfony\Component\Workflow\Transition;
|
use Symfony\Component\Workflow\Transition;
|
||||||
|
use Symfony\Component\Workflow\TransitionBlockerList;
|
||||||
use Twig\Extension\AbstractExtension;
|
use Twig\Extension\AbstractExtension;
|
||||||
use Twig\TwigFunction;
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ class WorkflowExtension extends AbstractExtension
|
|||||||
new TwigFunction('workflow_has_marked_place', [$this, 'hasMarkedPlace']),
|
new TwigFunction('workflow_has_marked_place', [$this, 'hasMarkedPlace']),
|
||||||
new TwigFunction('workflow_marked_places', [$this, 'getMarkedPlaces']),
|
new TwigFunction('workflow_marked_places', [$this, 'getMarkedPlaces']),
|
||||||
new TwigFunction('workflow_metadata', [$this, 'getMetadata']),
|
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()
|
public function getName()
|
||||||
{
|
{
|
||||||
return 'workflow';
|
return 'workflow';
|
||||||
|
@ -20,6 +20,7 @@ use Symfony\Component\Workflow\Registry;
|
|||||||
use Symfony\Component\Workflow\SupportStrategy\ClassInstanceSupportStrategy;
|
use Symfony\Component\Workflow\SupportStrategy\ClassInstanceSupportStrategy;
|
||||||
use Symfony\Component\Workflow\SupportStrategy\InstanceOfSupportStrategy;
|
use Symfony\Component\Workflow\SupportStrategy\InstanceOfSupportStrategy;
|
||||||
use Symfony\Component\Workflow\Transition;
|
use Symfony\Component\Workflow\Transition;
|
||||||
|
use Symfony\Component\Workflow\TransitionBlockerList;
|
||||||
use Symfony\Component\Workflow\Workflow;
|
use Symfony\Component\Workflow\Workflow;
|
||||||
|
|
||||||
class WorkflowExtensionTest extends TestCase
|
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->assertNull($this->extension->getMetadata($subject, 'not found', $this->t1));
|
$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
|
final class Subject
|
||||||
|
Reference in New Issue
Block a user