src/EventSubscriber/AddFormFieldApportSaleTransactionSubscriber.php line 27

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\EventSubscriber;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\Form\Extension\Core\Type\TextType;
  6. use Symfony\Component\Form\FormEvent;
  7. use Symfony\Component\Form\FormEvents;
  8. use Symfony\Contracts\Translation\TranslatorInterface;
  9. use App\Infrastructure\RequestDto\Reference\ReferencePropertyServiceTypeDto;
  10. class AddFormFieldApportSaleTransactionSubscriber implements EventSubscriberInterface
  11. {
  12.     private TranslatorInterface $translator;
  13.     /**
  14.      * @param TranslatorInterface $translator
  15.      */
  16.     public function __construct(
  17.         TranslatorInterface $translator
  18.     ) {
  19.         $this->translator $translator;
  20.     }
  21.     public function onPresetData(FormEvent $event): void
  22.     {
  23.         $transaction $event->getData();
  24.         $form $event->getForm();
  25.         if (!$transaction || $transaction->getMandate()->getProperty()->getReferenceServiceType()->getCode() !== ReferencePropertyServiceTypeDto::REFERENCE_CODE_PROPERTY_SERVICE_TYPE_SELL) {
  26.             return;
  27.         }
  28.         $form->add('apport'TextType::class, [
  29.             'label' => $this->translator->trans(
  30.                 'transaction.properties.apport',
  31.                 [],
  32.                 'transaction',
  33.             ),
  34.             "required" => false,
  35.             'data' => $transaction->getApport() ?: null,
  36.             'attr' => [
  37.                 'readonly' => false,
  38.                 'disabled' => false,
  39.                 'class' => 'form-control form-label mb-1',
  40.                 'value' => $transaction->getApport() != null $transaction->getApport() : null
  41.             ],
  42.             'label_attr' => [
  43.                 'class' => 'form-label font-weight-bold text-uppercase'
  44.             ],
  45.         ]);
  46.     }
  47.     public static function getSubscribedEvents(): array
  48.     {
  49.         return [
  50.             FormEvents::PRE_SET_DATA => 'onPreSetData'
  51.         ];
  52.     }
  53. }