function RouteProvider::getRouteByName

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

Find the route using the provided route name.

Parameters

string $name: The route name to fetch

Return value

\Symfony\Component\Routing\Route The found route.

Throws

\Symfony\Component\Routing\Exception\RouteNotFoundException Thrown if there is no route with that name in this repository.

File

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

Class

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

Namespace

Drupal\Core\Routing

Code

public function getRouteByName($name) {
    $routes = $this->getRoutesByNames([
        $name,
    ]);
    if (empty($routes)) {
        throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', $name));
    }
    return reset($routes);
}

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