You are here

public function RouteProvider::getRoutesByNames in Drupal 10

Same name in this branch
  1. 10 core/tests/Drupal/KernelTests/RouteProvider.php \Drupal\KernelTests\RouteProvider::getRoutesByNames()
  2. 10 core/lib/Drupal/Core/Routing/RouteProvider.php \Drupal\Core\Routing\RouteProvider::getRoutesByNames()
Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Routing/RouteProvider.php \Drupal\Core\Routing\RouteProvider::getRoutesByNames()
  2. 9 core/lib/Drupal/Core/Routing/RouteProvider.php \Drupal\Core\Routing\RouteProvider::getRoutesByNames()

Find many routes by their names using the provided list of names.

Note that this method may not throw an exception if some of the routes are not found or are not actually Route instances. It will just return the list of those Route instances it found.

This method exists in order to allow performance optimizations. The simple implementation could be to just repeatedly call $this->getRouteByName() while catching and ignoring eventual exceptions.

If $names is null, this method SHOULD return a collection of all routes known to this provider. If there are many routes to be expected, usage of a lazy loading collection is recommended. A provider MAY only return a subset of routes to e.g. support paging or other concepts.

Parameters

array|null $names: The list of names to retrieve, In case of null, the provider will determine what routes to return

Return value

\Symfony\Component\Routing\Route[] Iterable list with the keys being the names from the $names array

Overrides RouteProviderInterface::getRoutesByNames

1 call to RouteProvider::getRoutesByNames()
RouteProvider::getRouteByName in core/lib/Drupal/Core/Routing/RouteProvider.php
Find the route using the provided route name.

File

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

Class

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

Namespace

Drupal\Core\Routing

Code

public function getRoutesByNames($names) {
  $this
    ->preLoadRoutes($names);
  foreach ($names as $name) {

    // The specified route name might not exist or might be serialized.
    if (!isset($this->routes[$name]) && isset($this->serializedRoutes[$name])) {
      $this->routes[$name] = unserialize($this->serializedRoutes[$name]);
      unset($this->serializedRoutes[$name]);
    }
  }
  return array_intersect_key($this->routes, array_flip($names));
}