<?php
declare(strict_types=1);
namespace App\Form\EventListener\Global;
use App\Form\FormHelper;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
class AddUrlFieldSubscriber extends FormHelper implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
FormEvents::PRE_SET_DATA => 'preSetData',
FormEvents::POST_SUBMIT => 'postSubmit',
];
}
public function preSetData(FormEvent $event): void
{
$event->getForm()->add('url', TextType::class, $this->getTextParameters('app.global.fields.url', self::PLACEHOLDER_LINK, true));
}
public function postSubmit(FormEvent $event): void
{
/** @var Domain $domain */
$domain = $event->getData();
$domain->setUrl(strtolower($domain->getUrl()));
}
}