src/EventSubscriber/LeadTypeSubscriber.php line 24

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\EventSubscriber;
  3. use Symfony\Component\Form\FormEvents;
  4. use Symfony\Component\Form\Event\PostSubmitEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class LeadTypeSubscriber implements EventSubscriberInterface
  7. {
  8.     private const MAPPER = [
  9.             'Email' => ['email''mail'],
  10.             'LastName' => ['lastname''nom'],
  11.         ];
  12.     public static function getSubscribedEvents(): array
  13.     {
  14.         return [
  15.             FormEvents::POST_SUBMIT => ['setQueryParams']
  16.         ];
  17.     }
  18.     public function setQueryParams(PostSubmitEvent $event)
  19.     {
  20.         $lead $event->getData();
  21.         foreach (self::MAPPER as $key => $params) {
  22.             /** @todo Use the property Accessor to set/get values in a proper way. */
  23.             $getter 'get' $key;
  24.             $setter 'set' $key;
  25.             if ($lead->{$getter}() === null) {
  26.                 $query_params $lead->getQueryParams();
  27.                 foreach ($params as $param) {
  28.                     if (isset($query_params[$param])) {
  29.                         $lead->{$setter}($query_params[$param]);
  30.                     }
  31.                 }
  32.             }
  33.         }
  34.     }
  35. }