<?php
declare(strict_types=1);
namespace App\Form\EventListener\Admin\Webhook;
use App\Entity\Admin\Webhook\WebhookInterface;
use App\Form\FormHelper;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
class AddObjectFieldSubscriber extends FormHelper implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [FormEvents::PRE_SET_DATA => 'preSetData'];
}
public function preSetData(FormEvent $event): void
{
$choices = [];
foreach (WebhookInterface::OBJECTS as $object) {
$choices['app.admin.pages.webhook.object.' . $object] = $object;
}
$event->getForm()->add('object', ChoiceType::class, $this->getChoiceParameters('app.global.select.object', self::PLACEHOLDER_CHOICE, true, [
'choices' => $choices,
'disabled' => null !== $event->getdata()->getId(),
]));
}
}