src/Form/EventListener/Admin/Webhook/AddObjectFieldSubscriber.php line 21

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form\EventListener\Admin\Webhook;
  4. use App\Entity\Admin\Webhook\WebhookInterface;
  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 AddObjectFieldSubscriber 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 (WebhookInterface::OBJECTS as $object) {
  20.             $choices['app.admin.pages.webhook.object.' $object] = $object;
  21.         }
  22.         $event->getForm()->add('object'ChoiceType::class, $this->getChoiceParameters('app.global.select.object'self::PLACEHOLDER_CHOICEtrue, [
  23.             'choices' => $choices,
  24.             'disabled' => null !== $event->getdata()->getId(),
  25.         ]));
  26.     }
  27. }