src/FormSubscriber/GHRetiroCesantiasSubscriber.php line 30

Open in your IDE?
  1. <?php
  2. // src/Form/EventListener/AddNameFieldSubscriber.php
  3. namespace App\FormSubscriber;
  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\Component\Form\Form;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. class GHRetiroCesantiasSubscriber implements EventSubscriberInterface {
  11.     private $entityManager;
  12.     public function __construct(
  13.             EntityManagerInterface $entityManager
  14.     ) {
  15.         $this->entityManager $entityManager;
  16.     }
  17.     public static function getSubscribedEvents(): array {
  18.         // Tells the dispatcher that you want to listen on the form.pre_set_data
  19.         // event and that the preSetData method should be called.
  20.         return [FormEvents::PRE_SUBMIT => 'preSubmit'];
  21.     }
  22.     public function preSubmit(FormEvent $event): void {
  23.         $data $event->getData();
  24.         //data es un arreglo con los valores establecidos por el usuario en el form.
  25.         //como $data contiene el pais seleccionado por el usuario al enviar el formulario,
  26.         // usamos el valor de la posicion $data['country'] para filtrar el sql de los estados
  27.         if (isset($data['inversion'])) {
  28.             $idBusqueda $data['inversion'];
  29.             $inversion $this->entityManager->getRepository(\App\Entity\ParInversion::class)->find($idBusqueda);
  30.             $documentos $inversion->getDocumentosAnexar();
  31.             $data['documento'] = $documentos;
  32.             
  33.             $event->setData($data);
  34.         }
  35.     }
  36. }