<?php
declare(strict_types=1);
namespace App\Form\EventListener\Search;
use App\Form\FormHelper;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
class AddPeriodSubscriber extends FormHelper implements EventSubscriberInterface
{
public function __construct(
private ?string $label = null,
private ?string $placeholder = self::PLACEHOLDER_NONE,
) {
}
public static function getSubscribedEvents(): array
{
return [FormEvents::PRE_SET_DATA => 'preSetData'];
}
public function preSetData(FormEvent $event): void
{
$event->getForm()->add('period', TextType::class, $this->getTextParameters($this->label, $this->placeholder, false, ['attr' => ['readonly' => 'readonly', 'class' => 'pointer']]));
}
}