src/EventSubscriber/AddressSubmitSubscriber.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Service\Geographic;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\Form\FormEvent;
  6. use Symfony\Component\Form\FormEvents;
  7. /**
  8.  * Class AddressSubmitSubscriber
  9.  * Utilisé pour la soumission des sous-formulaires `AddressBlockType`
  10.  *
  11.  * @package App\EventSubscriber
  12.  */
  13. class AddressSubmitSubscriber implements EventSubscriberInterface
  14. {
  15.     /**
  16.      * @var Geographic
  17.      */
  18.     private $geographic;
  19.     public function __construct(Geographic $geographic)
  20.     {
  21.         $this->geographic $geographic;
  22.     }
  23.     public static function getSubscribedEvents(): array
  24.     {
  25.         return [FormEvents::PRE_SUBMIT => 'preSubmit'];
  26.     }
  27.     public function preSubmit(FormEvent $event): void
  28.     {
  29.         $data $event->getData();
  30.         $form $event->getForm();
  31.         /**
  32.          * Remplir le formulaire avec les donnée présentes dans un tableau
  33.          */
  34.         $this->geographic->setFormData($form$data);
  35.     }
  36.     public static function getSubscribedServices(): array
  37.     {
  38.         return [
  39.             // ...
  40.             Geographic::class,
  41.         ];
  42.     }
  43. }