<?php
namespace App\EventSubscriber;
use App\Service\Geographic;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
/**
* Class AddressSubmitSubscriber
* Utilisé pour la soumission des sous-formulaires `AddressBlockType`
*
* @package App\EventSubscriber
*/
class AddressSubmitSubscriber implements EventSubscriberInterface
{
/**
* @var Geographic
*/
private $geographic;
public function __construct(Geographic $geographic)
{
$this->geographic = $geographic;
}
public static function getSubscribedEvents(): array
{
return [FormEvents::PRE_SUBMIT => 'preSubmit'];
}
public function preSubmit(FormEvent $event): void
{
$data = $event->getData();
$form = $event->getForm();
/**
* Remplir le formulaire avec les donnée présentes dans un tableau
*/
$this->geographic->setFormData($form, $data);
}
public static function getSubscribedServices(): array
{
return [
// ...
Geographic::class,
];
}
}