src/Form/EventListener/Search/AddEnabledSubscriber.php line 20

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form\EventListener\Search;
  4. use App\Form\FormHelper;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  7. use Symfony\Component\Form\FormEvent;
  8. use Symfony\Component\Form\FormEvents;
  9. class AddEnabledSubscriber extends FormHelper implements EventSubscriberInterface
  10. {
  11.     public static function getSubscribedEvents(): array
  12.     {
  13.         return [FormEvents::PRE_SET_DATA => 'preSetData'];
  14.     }
  15.     public function preSetData(FormEvent $event): void
  16.     {
  17.         $choices = [
  18.             'app.global.filter.enabled.choices.all' => null,
  19.             'app.global.filter.enabled.choices.enabled' => true,
  20.             'app.global.filter.enabled.choices.disabled' => false,
  21.         ];
  22.         $event->getForm()->add('enabled'ChoiceType::class, $this->getChoiceParameters('app.global.select.enabled'self::PLACEHOLDER_NONEfalse, [
  23.             'choices' => $choices,
  24.             'data' => null,
  25.             'expanded' => true,
  26.         ]));
  27.     }
  28. }