You are here

public function RouteInfoController::routeDetail in Devel 8

Same name and namespace in other branches
  1. 8.3 src/Controller/RouteInfoController.php \Drupal\devel\Controller\RouteInfoController::routeDetail()
  2. 8.2 src/Controller/RouteInfoController.php \Drupal\devel\Controller\RouteInfoController::routeDetail()
  3. 4.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 171

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) {
      drupal_set_message($this
        ->t("Unable to load route for url '%url'", [
        '%url' => $path,
      ]), 'warning');
    }
  }

  // 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) {
      drupal_set_message($this
        ->t("Unable to load route '%name'", [
        '%name' => $route_name,
      ]), 'warning');
    }
  }

  // No route retrieved from path or name specified, get the current route.
  if ($route === NULL) {
    $route = $route_match
      ->getRouteObject();
  }
  return $this->dumper
    ->exportAsRenderable($route);
}