src/Form/EventListener/Global/AddNameDescriptionFieldSubscriber.php line 27

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. /** This Subscriber is temporary. It will be removed once admin entity has a code filed and a name instead of name and description */
  10. class AddNameDescriptionFieldSubscriber extends FormHelper implements EventSubscriberInterface
  11. {
  12.     public function __construct(
  13.         private string $label 'app.global.fields.name',
  14.         private string $placeholder self::PLACEHOLDER_SAME_AS_LABEL,
  15.     ) {
  16.     }
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [FormEvents::PRE_SET_DATA => 'preSetData'];
  20.     }
  21.     public function preSetData(FormEvent $event): void
  22.     {
  23.         $entity $event->getData();
  24.         $attr = ['class' => null === $entity || null === $entity->getId() ? 'slug-source' ''];
  25.         $event->getForm()->add('description'TextType::class, $this->getTextParameters($this->label$this->placeholdertruecompact('attr')));
  26.     }
  27. }