function RouteProvider::preLoadRoutes

Same name in this branch
  1. 8.9.x core/tests/Drupal/KernelTests/RouteProvider.php \Drupal\KernelTests\RouteProvider::preLoadRoutes()
Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/RouteProvider.php \Drupal\KernelTests\RouteProvider::preLoadRoutes()
  2. 9 core/lib/Drupal/Core/Routing/RouteProvider.php \Drupal\Core\Routing\RouteProvider::preLoadRoutes()
  3. 10 core/tests/Drupal/KernelTests/RouteProvider.php \Drupal\KernelTests\RouteProvider::preLoadRoutes()
  4. 10 core/lib/Drupal/Core/Routing/RouteProvider.php \Drupal\Core\Routing\RouteProvider::preLoadRoutes()
  5. 11.x core/tests/Drupal/KernelTests/RouteProvider.php \Drupal\KernelTests\RouteProvider::preLoadRoutes()
  6. 11.x core/lib/Drupal/Core/Routing/RouteProvider.php \Drupal\Core\Routing\RouteProvider::preLoadRoutes()

Overrides PreloadableRouteProviderInterface::preLoadRoutes

1 call to RouteProvider::preLoadRoutes()
RouteProvider::getRoutesByNames in core/lib/Drupal/Core/Routing/RouteProvider.php

File

core/lib/Drupal/Core/Routing/RouteProvider.php, line 217

Class

RouteProvider
A Route Provider front-end for all Drupal-stored routes.

Namespace

Drupal\Core\Routing

Code

public function preLoadRoutes($names) {
    if (empty($names)) {
        throw new \InvalidArgumentException('You must specify the route names to load');
    }
    $routes_to_load = array_diff($names, array_keys($this->routes), array_keys($this->serializedRoutes));
    if ($routes_to_load) {
        $cid = static::ROUTE_LOAD_CID_PREFIX . hash('sha512', serialize($routes_to_load));
        if ($cache = $this->cache
            ->get($cid)) {
            $routes = $cache->data;
        }
        else {
            try {
                $result = $this->connection
                    ->query('SELECT name, route FROM {' . $this->connection
                    ->escapeTable($this->tableName) . '} WHERE name IN ( :names[] )', [
                    ':names[]' => $routes_to_load,
                ]);
                $routes = $result->fetchAllKeyed();
                $this->cache
                    ->set($cid, $routes, Cache::PERMANENT, [
                    'routes',
                ]);
            } catch (\Exception $e) {
                $routes = [];
            }
        }
        $this->serializedRoutes += $routes;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.