<?php
declare(strict_types=1);
namespace App\Form\EventListener\Order;
use App\Form\FormHelper;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
class AddEntityNameSubscriber extends FormHelper implements EventSubscriberInterface
{
private ?string $entityName;
public function __construct(?string $entityName = null)
{
$this->entityName = $entityName;
}
public static function getSubscribedEvents(): array
{
return [FormEvents::PRE_SET_DATA => 'preSetData'];
}
public function preSetData(FormEvent $event): void
{
$event->getForm()->add('entityName', HiddenType::class, $this->getHiddenParameters($this->entityName));
}
}