src/Form/EventListener/Search/Order/AddTimeSubscriber.php line 21

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form\EventListener\Search\Order;
  4. use App\Entity\Order\OrderInterface;
  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 AddTimeSubscriber 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 (OrderInterface::FILTERS as $type) {
  20.             $choices['app.order.type.' $type] = OrderInterface::TYPE_ALL !== $type $type null;
  21.         }
  22.         $event->getForm()->add('type'ChoiceType::class, $this->getChoiceParameters(
  23.             null,
  24.             self::PLACEHOLDER_NONE,
  25.             false,
  26.             [
  27.                 'choices' => $choices,
  28.                 'choice_attr' => function ($choice) {
  29.                     return ['data-type' => $choice];
  30.                 },
  31.                 'data' => OrderInterface::TYPE_TODAY,
  32.                 'expanded' => true,
  33.                 'multiple' => false,
  34.             ]
  35.         ));
  36.     }
  37. }