src/EventSubscriber/NotificacionFormSubscriber.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. //use App\Form\EnviarPlantillaNotificacionType;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. //use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  6. use Symfony\Component\Form\FormFactoryInterface;
  7. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  8. use Symfony\Component\HttpKernel\KernelEvents;
  9. //use Twig\Environment;
  10. class NotificacionFormSubscriber implements EventSubscriberInterface
  11. {
  12. public function __construct(
  13. // private readonly FormFactoryInterface $formFactory,
  14. // private readonly Environment $twig
  15. )
  16. {
  17. }
  18. public static function getSubscribedEvents(): array
  19. {
  20. return [
  21. KernelEvents::CONTROLLER => 'onKernelController',
  22. ];
  23. }
  24. public function onKernelController(ControllerEvent $event): void
  25. {
  26. // $request = $event->getRequest();
  27. //
  28. // $route = $request->attributes->get('_route');
  29. //// $routeParams = json_encode($request->attributes->get('_route_params')) ?? [];
  30. //// $routeView = $this->getTemplateForRoute($request->attributes->get('_route'));
  31. //// $routeController = $request->attributes->get('_controller') ?? null;
  32. ////
  33. //// dump($this->checkAllowedRoute($route));
  34. //// die;
  35. //
  36. // // Si la route está definida en la función getTemplateForRoute, añadimos el formulario a la vista.
  37. // if ($this->checkAllowedRoute($route)) {
  38. // $form = $this->formFactory->create(
  39. // EnviarPlantillaNotificacionType::class,
  40. // null,
  41. // [
  42. // //'action' => $this->router->generate('back_enviar_plantilla_notificacion_usuario')
  43. // ]
  44. // );
  45. //
  46. // $form
  47. // ->add('_route', HiddenType::class, ['data' => $route])
  48. //// ->add('_route_params', HiddenType::class, ['data' => $routeParams])
  49. //// ->add('_route_view', HiddenType::class, ['data' => $routeView])
  50. //// ->add('_route_controller', HiddenType::class, ['data' => $routeController])
  51. // ;
  52. //
  53. // $this->twig->addGlobal('formEnviarNotificacion', $form->createView());
  54. // }
  55. }
  56. // // Hay que definir las rutas permitidas para no adjuntar el form en todas.
  57. // private function checkAllowedRoute(string $route): bool
  58. // {
  59. // return in_array($route, [
  60. // 'back_listado_usuarios',
  61. // 'back_listado_alumnos',
  62. // 'back_listado_solicitudes',
  63. // 'back_ver_usuario',
  64. // 'back_ver_solicitud',
  65. // 'back_ver_alumno'
  66. // ]);
  67. // }
  68. //
  69. // // Hay que definir las rutas junto con la plantilla de donde se usará el form de enviar notificación.
  70. // private function getTemplateForRoute(?string $route): ?string
  71. // {
  72. // return match ($route) {
  73. // 'back_listado_usuarios' => 'usuario/listado.html.twig',
  74. // 'back_listado_alumnos' => 'alumnos/listado.html.twig',
  75. // 'back_listado_solicitudes' => 'solicitud/listado.html.twig',
  76. // 'back_ver_usuario' => 'usuario/ver-vision-general.html.twig',
  77. // 'back_ver_solicitud' => 'solicitud/ver.html.twig',
  78. // 'back_ver_alumno' => 'alumno/ver.html.twig',
  79. // default => null
  80. // };
  81. // }
  82. }