<?php
namespace App\EventSubscriber;
use App\Entity\Form;
use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityPersistedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class FormSubscriber implements EventSubscriberInterface
{
/**
* @return array[]
*/
public static function getSubscribedEvents(): array
{
return [
BeforeEntityPersistedEvent::class => ['preSetData']
];
}
/**
* @param BeforeEntityPersistedEvent $event
* @return void
*/
public function preSetData(BeforeEntityPersistedEvent $event)
{
$form = $event->getEntityInstance();
if (!($form instanceof Form)) {
return;
}
if (!$form->getDefinitionFile() && !$form->getMasterForm()) {
return;
}
if (!$form->getMasterForm()) {
return;
}
if ($masterForm = $form->getMasterForm()) {
$form->setDefinitionFile($masterForm->getDefinitionFile());
}
}
}