src/Form/EventListener/Address/AddAddressFieldSubscriber.php line 27

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form\EventListener\Address;
  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 AddAddressFieldSubscriber extends FormHelper implements EventSubscriberInterface
  10. {
  11.     public function __construct(
  12.         private string $label 'app.global.fields.address',
  13.         private string $placeholder self::PLACEHOLDER_ADDRESS,
  14.         private string $class 'shop_address',
  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.         $event->getForm()->add('address'TextType::class, $this->getTextAreaParameters(
  24.             $this->label,
  25.             $this->placeholder,
  26.             false,
  27.             ['attr' => ['class' => $this->class]],
  28.         ));
  29.     }
  30. }