src/EventSubscriber/FormSubscriber.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Entity\Form;
  4. use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityPersistedEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class FormSubscriber implements EventSubscriberInterface
  7. {
  8.     /**
  9.      * @return array[]
  10.      */
  11.     public static function getSubscribedEvents(): array
  12.     {
  13.         return [
  14.             BeforeEntityPersistedEvent::class => ['preSetData']
  15.         ];
  16.     }
  17.     /**
  18.      * @param BeforeEntityPersistedEvent $event
  19.      * @return void
  20.      */
  21.     public function preSetData(BeforeEntityPersistedEvent $event)
  22.     {
  23.         $form $event->getEntityInstance();
  24.         if (!($form instanceof Form)) {
  25.             return;
  26.         }
  27.         if (!$form->getDefinitionFile() && !$form->getMasterForm()) {
  28.             return;
  29.         }
  30.         if (!$form->getMasterForm()) {
  31.             return;
  32.         }
  33.         if ($masterForm $form->getMasterForm()) {
  34.             $form->setDefinitionFile($masterForm->getDefinitionFile());
  35.         }
  36.     }
  37. }