Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. RouteProvider.php

function 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.

Overrides RouteProviderInterface::getRouteByName

File

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

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);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal