src/EventSubscriber/System/TwigGlobalSubscriber.php line 45

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber\System;
  3. use App\Entity\Channel\Channel;
  4. use App\Entity\System\CampaignStatus;
  5. use App\Entity\System\ProductStatus;
  6. use App\Service\SystemService;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\RequestStack;
  11. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  12. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  13. use Symfony\Component\HttpKernel\KernelEvents;
  14. use Symfony\Component\Routing\RouterInterface;
  15. use Twig\Environment;
  16. use App\Entity\System\TemplateStatus;
  17. class TwigGlobalSubscriber implements EventSubscriberInterface {
  18.     /**
  19.      * @var \Twig\Environment
  20.      */
  21.     private $twig;
  22.     /**
  23.      * @var EntityManagerInterface
  24.      */
  25.     private $entityManager;
  26.     /** @var RouterInterface */
  27.     private $router;
  28.     /** @var Request|null */
  29.     private $request;
  30.     public function __construct(Environment $twigEntityManagerInterface $entityManagerRouterInterface $routerRequestStack $requestStack) {
  31.         $this->twig    $twig;
  32.         $this->entityManager $entityManager;
  33.         $this->router $router;
  34.         $this->request $requestStack->getCurrentRequest();
  35.     }
  36.     public function injectGlobalVariables(ControllerEvent $event) {
  37.         $lastProductStatus $this->entityManager->getRepository(ProductStatus::class)->findLastRecord();
  38.         $lastProductStatusArray $this->entityManager->getRepository(ProductStatus::class)->findLastRecordAsArray();
  39.         $lastTemplateStatus $this->entityManager->getRepository(TemplateStatus::class)->findLastRecord();
  40.         $lastTemplateStatusArray $this->entityManager->getRepository(TemplateStatus::class)->findLastRecordAsArray();
  41.         $lastCampaignStatus $this->entityManager->getRepository(CampaignStatus::class)->findLastRecord();
  42.         $lastCampaignStatusArray $this->entityManager->getRepository(CampaignStatus::class)->findLastRecordAsArray();
  43.         $request $event->getRequest();
  44.         $isCurrentPathRoVignette $request && $request->getPathInfo() == $this->router->generate('app_shop_vignette');
  45.         $isCurrentPathHuVignette $request && $request->getPathInfo() == $this->router->generate('app_shop_hu_vignette');
  46.         $isCurrentPathRca $request && $request->getPathInfo() == $this->router->generate('app_shop_rca_details');
  47.         $this->twig->addGlobal('lastProductStatus'$lastProductStatus);
  48.         $this->twig->addGlobal('lastProductStatusArray'$lastProductStatusArray);
  49.         $this->twig->addGlobal('lastTemplateStatus'$lastTemplateStatus);
  50.         $this->twig->addGlobal('lastTemplateStatusArray'$lastTemplateStatusArray);
  51.         $this->twig->addGlobal('lastCampaignStatus'$lastCampaignStatus);
  52.         $this->twig->addGlobal('lastCampaignStatusArray'$lastCampaignStatusArray);
  53.         $this->twig->addGlobal('isCurrentPathRoVignette'$isCurrentPathRoVignette);
  54.         $this->twig->addGlobal('isCurrentPathHuVignette'$isCurrentPathHuVignette);
  55.         $this->twig->addGlobal('isCurrentPathRca'$isCurrentPathRca);
  56.         $this->twig->addGlobal('rcaSiteUrl'$_ENV['RCA_SITE_URL']);
  57.         $this->twig->addGlobal('roVignetteSiteUrl'$_ENV['ROVINIETE_SITE_URL']);
  58.         $this->twig->addGlobal('isTicketing'$_ENV['IS_TICKETING']);
  59.     }
  60.     public static function getSubscribedEvents() {
  61.         return [KernelEvents::CONTROLLER =>  'injectGlobalVariables'];
  62.     }
  63. }