src/Form/EventListener/Global/AddPriceFieldSubscriber.php line 26

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\MoneyType;
  7. use Symfony\Component\Form\FormEvent;
  8. use Symfony\Component\Form\FormEvents;
  9. class AddPriceFieldSubscriber extends FormHelper implements EventSubscriberInterface
  10. {
  11.     public function __construct(
  12.         private string $label 'app.global.fields.price',
  13.         private string $placeholder self::PLACEHOLDER_SAME_AS_LABEL,
  14.     ) {
  15.     }
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         return [FormEvents::PRE_SET_DATA => 'preSetData'];
  19.     }
  20.     public function preSetData(FormEvent $event): void
  21.     {
  22.         $attr = ['class' => 'price'];
  23.         $event->getForm()->add('price'MoneyType::class, $this->getMoneyParameters($this->label$this->placeholdertruecompact('attr')));
  24.     }
  25. }