src/EventSubscriber/FundingWorkflowSubscriber.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Entity\Funding;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\Workflow\Event\GuardEvent;
  6. use Symfony\Component\Workflow\TransitionBlocker;
  7. class FundingWorkflowSubscriber implements EventSubscriberInterface
  8. {
  9.     public static function getSubscribedEvents()
  10.     {
  11.         return [
  12.             'workflow.funding.guard.to_validated' => ['guardToValidated'],
  13.         ];
  14.     }
  15.     public function guardToValidated(GuardEvent $event)
  16.     {
  17.         /** @var Funding $funding */
  18.         $funding $event->getSubject();
  19.         if (!$funding->getFinancer()) {
  20.             $event->addTransitionBlocker(new TransitionBlocker("L'offre de financement doit être relié à un organisme de financement."'0'));
  21.         }
  22.     }
  23. }