src/Form/EventListener/Global/AddImageSvgFieldSubscriber.php line 25

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\FormEvent;
  7. use Symfony\Component\Form\FormEvents;
  8. use Vich\UploaderBundle\Form\Type\VichImageType;
  9. class AddImageSvgFieldSubscriber extends FormHelper implements EventSubscriberInterface
  10. {
  11.     public function __construct(
  12.         private ?string $label null
  13.     ) {
  14.     }
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [FormEvents::PRE_SET_DATA => 'preSetData'];
  18.     }
  19.     public function preSetData(FormEvent $event): void
  20.     {
  21.         $event->getForm()->add('svgFile'VichImageType::class, $this->getSvgImageParameters($this->label));
  22.     }
  23. }