<?php
declare(strict_types=1);
namespace App\Form\EventListener\Global;
use App\Form\FormHelper;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Vich\UploaderBundle\Form\Type\VichImageType;
class AddImageSvgFieldSubscriber extends FormHelper implements EventSubscriberInterface
{
public function __construct(
private ?string $label = null
) {
}
public static function getSubscribedEvents(): array
{
return [FormEvents::PRE_SET_DATA => 'preSetData'];
}
public function preSetData(FormEvent $event): void
{
$event->getForm()->add('svgFile', VichImageType::class, $this->getSvgImageParameters($this->label));
}
}