src/FormSubscriber/GHEntrenamientoProcesoSubscriber.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 GHEntrenamientoProcesoSubscriber 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['proceso'])) {
  28.             $idBusqueda $data['proceso'];
  29.             $proceso $this->entityManager->getRepository(\App\Entity\ParProceso::class)->find($idBusqueda);
  30.             $desInduccion "";
  31.             $event->getForm()
  32.                     ->add('responsable'\Symfony\Bridge\Doctrine\Form\Type\EntityType::class, ['class' => \App\Entity\TerPersona::class, 'query_builder' => function (\Doctrine\ORM\EntityRepository $er) use ($idBusqueda) {
  33.                             return $er->createQueryBuilder('p')
  34.                             ->leftJoin('p.perfilCargo''pc')
  35.                             ->leftJoin('pc.ParProceso''pro')
  36.                             ->leftJoin('p.estado''e')
  37.                             ->where('pro.id = :idProceso')
  38.                             ->andWhere('e.id = 1')
  39.                             ->setParameter('idProceso'$idBusqueda)
  40.                             ->orderBy('p.nombres''ASC');
  41.                         }, 'label' => 'Responsable',
  42.                         'attr' => ['class' => 'form-control'], 'placeholder' => 'Seleccione una Opción.'])
  43.             ;
  44.             foreach ($proceso->getMatrizEntrenamientoProceso() as $reg) {
  45.                 $desInduccion $reg->getDescripcion();
  46.             }
  47.             $data['descripcionEntrenamiento'] = $desInduccion;
  48.             $event->setData($data);
  49.         }
  50.     }
  51. }