rewrite workflow and handle finalize differently

This commit is contained in:
2022-01-28 23:42:21 +01:00
parent fdafe7c82b
commit 86e7b0f007
11 changed files with 180 additions and 60 deletions

View File

@@ -21,6 +21,7 @@ use Symfony\Component\Security\Core\Security;
use Symfony\Component\Workflow\Event\Event;
use Symfony\Component\Workflow\Event\GuardEvent;
use Symfony\Component\Workflow\TransitionBlocker;
use function array_key_exists;
class EntityWorkflowTransitionEventSubscriber implements EventSubscriberInterface
{
@@ -44,6 +45,7 @@ class EntityWorkflowTransitionEventSubscriber implements EventSubscriberInterfac
{
return [
'workflow.transition' => 'onTransition',
'workflow.completed' => 'onCompleted',
'workflow.guard' => [
['guardEntityWorkflow', 0],
],
@@ -59,7 +61,7 @@ class EntityWorkflowTransitionEventSubscriber implements EventSubscriberInterfac
/** @var EntityWorkflow $entityWorkflow */
$entityWorkflow = $event->getSubject();
if ($entityWorkflow->isFinalize()) {
if ($entityWorkflow->isFinal()) {
$event->addTransitionBlocker(
new TransitionBlocker(
'workflow.The workflow is finalized',
@@ -88,7 +90,25 @@ class EntityWorkflowTransitionEventSubscriber implements EventSubscriberInterfac
}
}
public function onTransition(Event $event)
public function onCompleted(Event $event): void
{
if (!$event->getSubject() instanceof EntityWorkflow) {
return;
}
/** @var EntityWorkflow $entityWorkflow */
$entityWorkflow = $event->getSubject();
$step = $entityWorkflow->getCurrentStep();
$placeMetadata = $event->getWorkflow()->getMetadataStore()
->getPlaceMetadata($step->getCurrentStep());
if (array_key_exists('isFinal', $placeMetadata) && true === $placeMetadata['isFinal']) {
$step->setIsFinal(true);
}
}
public function onTransition(Event $event): void
{
if (!$event->getSubject() instanceof EntityWorkflow) {
return;