Validation when workflow state change

Hello Guys,

I am using pimcore 6 and I have implement workflow management, I want to validate the form before workflow state transition changes.

Please help

Pimcore Workflow is based on Symfony workflow component.You can refer to symfony documentation for this.

Hi,
Thank you for your reply, I have created event listener to catch the event when transition is happen.

class WorkflowListener implements EventSubscriberInterface
{
public function guardPublish(GuardEvent $event)
{

    $eventTransition = $event->getTransition();
    $hourLimit = $event->getMetadata('hour_limit', $eventTransition);

    if (date('H') <= $hourLimit) {
        return;
    }

    // Block the transition "publish" if it is more than 8 PM
    // with the message for end user
    $explanation = $event->getMetadata('explanation', $eventTransition);
    $event->addTransitionBlocker(new TransitionBlocker($explanation , 0));
}

public static function getSubscribedEvents()
{

    return [
        'workflow.RequestforCorrection_publishing.guard.publish' => ['guardPublish'],
    ];
}

}
I have also add it in my service.yml

AppBundle\EventListener\WorkflowListener:
tags:
- { name: kernel.event_listener, event: pimcore.dataobject.guardPublish, method: guardPublish }

Although i am not able to catch the event when transition is happen in work flow

Please Help.

Did you find any solution? I am facing the same isuse.

I have resolve issue given way
pls try

public function MarkAsinReview(GuardEvent $event)
{
   $transitionData = $event->getTransition();
   $transitionName = $transitionData->getName();
   if($transitionName == 'in_review')
    {
    			$flag = 0;
    			foreach ($fieldarray as $value)
    			{
    				 $xyzvalue = $value->getXyzvalue();
    				 $status = $value->getstatus();
    				if($xyzvalue  == '' || $status == '')
    				{
    					$flag = 1;
    				}
    			}
    			if($flag == '1')
    			{
    				$explanation = 'Status is mendatory fields, it should not be empty';
    				$newblocker = (new TransitionBlocker($explanation , 0));
    				$event->addTransitionBlocker($newblocker);
    				return;
    			}
    }
}
1 Like