<?php
declare(strict_types=1);
namespace App\Form\EventListener\Franchise\Company;
use App\Entity\Franchise\Franchise;
use App\Form\Franchise\CompanyType;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
class AddCompanyFieldSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [FormEvents::PRE_SET_DATA => 'preSetData'];
}
public function preSetData(FormEvent $event): void
{
/** @var Franchise $franchise */
$franchise = $event->getData();
if (null !== $franchise && null !== $franchise->getId()) {
return;
}
$event->getForm()->add('company', CompanyType::class);
}
}