src/Form/EventListener/Search/Order/AddStatusSubscriber.php line 31

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form\EventListener\Search\Order;
  4. use App\Entity\Order\CheckoutInterface;
  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. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. class AddStatusSubscriber extends FormHelper implements EventSubscriberInterface
  13. {
  14.     private ?Request $request;
  15.     public function __construct(
  16.         RequestStack $requestStack,
  17.     ) {
  18.         $this->request $requestStack->getCurrentRequest();
  19.     }
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [FormEvents::PRE_SET_DATA => 'preSetData'];
  23.     }
  24.     public function preSetData(FormEvent $event): void
  25.     {
  26.         $searchForm $this->request->query->get('search_form');
  27.         if (null === $searchForm || '2' !== $searchForm['type']) {
  28.             return;
  29.         }
  30.         $choices = [];
  31.         foreach (CheckoutInterface::STATES as $state) {
  32.             $choices['app.order.state.' $state] = $state;
  33.         }
  34.         $event->getForm()->add('status'ChoiceType::class, $this->getChoiceParameters(
  35.             'app.global.search.label.status',
  36.             self::PLACEHOLDER_NONE,
  37.             false,
  38.             [
  39.                 'choices' => $choices,
  40.                 'multiple' => true,
  41.             ]
  42.         ));
  43.     }
  44. }