src/Form/EventListener/Global/AddDayFieldSubscriber.php line 27

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form\EventListener\Global;
  4. use App\Entity\Shop\ShopInterface;
  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 AddDayFieldSubscriber extends FormHelper implements EventSubscriberInterface
  11. {
  12.     public function __construct(
  13.         private string $label 'app.shop_owner.pages.schedule.list.day',
  14.         private string $placeholder self::PLACEHOLDER_SAME_AS_LABEL,
  15.     ) {
  16.     }
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [FormEvents::PRE_SET_DATA => 'preSetData'];
  20.     }
  21.     public function preSetData(FormEvent $event): void
  22.     {
  23.         $event->getForm()->add(
  24.             'day',
  25.             ChoiceType::class,
  26.             $this->getChoiceParameters($this->label$this->placeholdertrue, [
  27.                 'choices' => ShopInterface::WEEKDAYS,
  28.             ])
  29.         );
  30.     }
  31. }