function RouteInfoController::routeDetail

Same name in other branches
  1. 5.x src/Controller/RouteInfoController.php \Drupal\devel\Controller\RouteInfoController::routeDetail()

Returns a render array representation of the route object.

The method tries to resolve the route from the 'path' or the 'route_name' query string value if available. If no route is retrieved from the query string parameters it fallbacks to the current route.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object.

\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match.

Return value

array A render array as expected by the renderer.

1 string reference to 'RouteInfoController::routeDetail'
devel.routing.yml in ./devel.routing.yml
devel.routing.yml

File

src/Controller/RouteInfoController.php, line 163

Class

RouteInfoController
Provides route responses for the route info pages.

Namespace

Drupal\devel\Controller

Code

public function routeDetail(Request $request, RouteMatchInterface $route_match) {
    $route = NULL;
    // Get the route object from the path query string if available.
    if ($path = $request->query
        ->get('path')) {
        try {
            $route = $this->router
                ->match($path);
        } catch (\Exception $e) {
            $this->messenger()
                ->addWarning($this->t("Unable to load route for url '%url'", [
                '%url' => $path,
            ]));
        }
    }
    // Get the route object from the route name query string if available and
    // the route is not retrieved by path.
    if ($route === NULL && ($route_name = $request->query
        ->get('route_name'))) {
        try {
            $route = $this->routeProvider
                ->getRouteByName($route_name);
        } catch (\Exception $e) {
            $this->messenger()
                ->addWarning($this->t("Unable to load route '%name'", [
                '%name' => $route_name,
            ]));
        }
    }
    // No route retrieved from path or name specified, get the current route.
    if ($route === NULL) {
        $route = $route_match->getRouteObject();
    }
    return $this->dumper
        ->exportAsRenderable($route);
}