src/Form/EventListener/Search/Order/AddSourceSubscriber.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\Admin\SourceInterface;
  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 AddSourceSubscriber 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 (SourceInterface::SOURCE_SEARCH_FILTER as $source) {
  20.             $choices['app.manager.pages.orders.search.sources.' $source] = SourceInterface::SOURCE_ALL !== $source $source null;
  21.         }
  22.         $event->getForm()->add('orderSource'ChoiceType::class, $this->getChoiceParameters(
  23.             'app.manager.pages.orders.details.source',
  24.             self::PLACEHOLDER_NONE,
  25.             false,
  26.             [
  27.                 'choices' => $choices,
  28.                 'choice_attr' => fn ($choice) => ['data-type' => $choice],
  29.                 'data' => null,
  30.                 'expanded' => true,
  31.                 'multiple' => false,
  32.             ]
  33.         ));
  34.     }
  35. }