<?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\ChoiceType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
class AddEnabledSubscriber extends FormHelper implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [FormEvents::PRE_SET_DATA => 'preSetData'];
}
public function preSetData(FormEvent $event): void
{
$choices = [
'app.global.filter.enabled.choices.all' => null,
'app.global.filter.enabled.choices.enabled' => true,
'app.global.filter.enabled.choices.disabled' => false,
];
$event->getForm()->add('enabled', ChoiceType::class, $this->getChoiceParameters('app.global.select.enabled', self::PLACEHOLDER_NONE, false, [
'choices' => $choices,
'data' => null,
'expanded' => true,
]));
}
}