src/Form/EventListener/Search/AddPeriodicitySubscriber.php line 21

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