src/Form/EventListener/Search/Franchise/AddStatusSubscriber.php line 21

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form\EventListener\Search\Franchise;
  4. use App\Entity\Franchise\FranchiseInterface;
  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 AddStatusSubscriber 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 = ['app.global.filter.status.choices.all' => null];
  19.         foreach (FranchiseInterface::STATUS as $status) {
  20.             $choices['app.global.filter.status.choices.' $status] = $status;
  21.         }
  22.         $event->getForm()->add('status'ChoiceType::class, $this->getChoiceParameters(
  23.             'app.global.filter.status.label',
  24.             self::PLACEHOLDER_NONE,
  25.             false,
  26.             [
  27.                 'choices' => $choices,
  28.                 'data' => null,
  29.             ]
  30.         ));
  31.     }
  32. }