diff --git a/core/lib/Drupal/Core/Routing/NonAdminRoutesPreloader.php b/core/lib/Drupal/Core/Routing/NonAdminRoutesPreloader.php index d9dcd77..a478c94 100644 --- a/core/lib/Drupal/Core/Routing/NonAdminRoutesPreloader.php +++ b/core/lib/Drupal/Core/Routing/NonAdminRoutesPreloader.php @@ -14,7 +14,11 @@ use Symfony\Component\HttpKernel\KernelEvents; /** - * Defines a class which preloads non admin routes. + * Defines a class which preloads non-admin routes. + * + * On an actual site we want to avoid too many database queries so we build a + * list of all routes which most likely appear on the actual site, which are all + * HTML routes not starting with "/admin". */ class NonAdminRoutesPreloader implements EventSubscriberInterface { @@ -82,13 +86,13 @@ protected function getNonAdminRoutes() { } /** - * Load all the admin routes right before the actual page is rendered. + * Loads all non-admin routes right before the actual page is rendered. * * @param \Symfony\Component\HttpKernel\Event\KernelEvent $event - * The Event to process. + * The event to process. */ public function onRequest(KernelEvent $event) { - // Just preload on normal html pages, as they will contain the menu links. + // Just preload on normal HTML pages, as they will display menu links. if ($this->negotiation->getContentType($event->getRequest()) == 'html') { $this->loadNonAdminRoutes(); } @@ -104,16 +108,16 @@ protected function loadNonAdminRoutes() { } /** - * Alters existing routes for a specific collection. + * Store the non admin routes in state when the route building is finished. * * @param \Drupal\Core\Routing\RouteBuildEvent $event * The route build event. */ - public function onAlterRoutes(RouteBuildEvent $event) { + public function onFinishedRoutes(RouteBuildEvent $event) { $collection = $event->getRouteCollection(); foreach ($collection->all() as $name => $route) { - // Just preload non admin and _content routes, as they are the ones - // that appear on menu links and co. + // Just preload non-admin and _content routes, as they are the ones that + // are used on menu links. if (strpos($route->getPath(), '/admin') === FALSE && $route->hasDefault('_content')) { $this->nonAdminRoutesOnRebuild[] = $name; } @@ -126,8 +130,9 @@ public function onAlterRoutes(RouteBuildEvent $event) { * {@inheritdoc} */ public static function getSubscribedEvents() { - $events[RoutingEvents::ALTER] = array('onAlterRoutes', -1024); - // Come before the HtmlViewSubscriber. + $events[RoutingEvents::FINISHED] = array('onFinishedRoutes'); + // Load the routes before the controller is executed (which happens after + // the kernel request event). $events[KernelEvents::REQUEST][] = array('onRequest'); return $events; }