<?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\TextareaType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
class AddDescriptionFieldSubscriber extends FormHelper implements EventSubscriberInterface
{
public function __construct(
private string $label = 'app.global.fields.description',
private string $placeholder = self::PLACEHOLDER_SAME_AS_LABEL,
) {
}
public static function getSubscribedEvents(): array
{
return [FormEvents::PRE_SET_DATA => 'preSetData'];
}
public function preSetData(FormEvent $event): void
{
$event->getForm()->add('description', TextareaType::class, $this->getTextAreaParameters($this->label, $this->placeholder, false, ['attr' => ['rows' => 2]]));
}
}