src/EventSubscriber/AddFormFieldFinanceModeSaleTransactionSubscriber.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\FormEvent;
  6. use Symfony\Component\Form\FormEvents;
  7. use Symfony\Contracts\Translation\TranslatorInterface;
  8. use App\Form\Type\Reference\ReferenceFinancingModeChoiceType;
  9. use App\Infrastructure\RequestDto\Reference\ReferencePropertyServiceTypeDto;
  10. class AddFormFieldFinanceModeSaleTransactionSubscriber 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('referenceFinancingMode'ReferenceFinancingModeChoiceType::class, [
  29.             'label' => $this->translator->trans(
  30.                 'transaction.properties.financeMode',
  31.                 [],
  32.                 'transaction'
  33.             ),
  34.             'label_attr' => [
  35.                 'class' => 'form-label font-weight-bold text-uppercase'
  36.             ],
  37.             'required' => true,
  38.             'choice_label' => 'name',
  39.             'choice_value' => 'id',
  40.             'expanded' => false,
  41.             'multiple' => false,
  42.             'attr' => [
  43.                 'class' => 'form-control mb-1'
  44.             ]
  45.         ]);
  46.     }
  47.     public static function getSubscribedEvents(): array
  48.     {
  49.         return [
  50.             FormEvents::PRE_SET_DATA => 'onPreSetData'
  51.         ];
  52.     }
  53. }