Exemple #1
0
 /**
  * Loads all non-admin routes right before the actual page is rendered.
  *
  * @param \Symfony\Component\HttpKernel\Event\KernelEvent $event
  *   The event to process.
  */
 public function onRequest(KernelEvent $event)
 {
     // Only preload on normal HTML pages, as they will display menu links.
     if ($this->routeProvider instanceof PreloadableRouteProviderInterface && $event->getRequest()->getRequestFormat() == 'html') {
         if ($routes = $this->state->get('routing.non_admin_routes', [])) {
             // Preload all the non-admin routes at once.
             $this->routeProvider->preLoadRoutes($routes);
         }
     }
 }
Exemple #2
0
 /**
  * Loads all non-admin routes right before the actual page is rendered.
  *
  * @param \Symfony\Component\HttpKernel\Event\KernelEvent $event
  *   The event to process.
  */
 public function onRequest(KernelEvent $event)
 {
     // Only preload on normal HTML pages, as they will display menu links.
     if ($this->routeProvider instanceof PreloadableRouteProviderInterface && $event->getRequest()->getRequestFormat() == 'html') {
         // Ensure that the state query is cached to skip the database query, if
         // possible.
         $key = 'routing.non_admin_routes';
         if ($cache = $this->cache->get($key)) {
             $routes = $cache->data;
         } else {
             $routes = $this->state->get($key, []);
             $this->cache->set($key, $routes, Cache::PERMANENT, ['routes']);
         }
         if ($routes) {
             // Preload all the non-admin routes at once.
             $this->routeProvider->preLoadRoutes($routes);
         }
     }
 }