<?php
namespace App\EventSubscriber;
use App\Entity\Funding;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Workflow\Event\GuardEvent;
use Symfony\Component\Workflow\TransitionBlocker;
class FundingWorkflowSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
'workflow.funding.guard.to_validated' => ['guardToValidated'],
];
}
public function guardToValidated(GuardEvent $event)
{
/** @var Funding $funding */
$funding = $event->getSubject();
if (!$funding->getFinancer()) {
$event->addTransitionBlocker(new TransitionBlocker("L'offre de financement doit être relié à un organisme de financement.", '0'));
}
}
}