src/Form/EventListener/Global/AddUrlFieldSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form\EventListener\Global;
  4. use App\Form\FormHelper;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\Form\Extension\Core\Type\TextType;
  7. use Symfony\Component\Form\FormEvent;
  8. use Symfony\Component\Form\FormEvents;
  9. class AddUrlFieldSubscriber extends FormHelper implements EventSubscriberInterface
  10. {
  11.     public static function getSubscribedEvents(): array
  12.     {
  13.         return [
  14.             FormEvents::PRE_SET_DATA => 'preSetData',
  15.             FormEvents::POST_SUBMIT => 'postSubmit',
  16.         ];
  17.     }
  18.     public function preSetData(FormEvent $event): void
  19.     {
  20.         $event->getForm()->add('url'TextType::class, $this->getTextParameters('app.global.fields.url'self::PLACEHOLDER_LINKtrue));
  21.     }
  22.     public function postSubmit(FormEvent $event): void
  23.     {
  24.         /** @var Domain $domain */
  25.         $domain $event->getData();
  26.         $domain->setUrl(strtolower($domain->getUrl()));
  27.     }
  28. }