1 layout.module layout_route_handler($router_item)

Route handler callback; Execute the current route item or wrap in a layout.

Parameters

$router_item: The menu router item for the page currently being loaded.

Return value

The fully built HTML content for this page, which will be wrapped in page.tpl.php.

Related topics

File

core/modules/layout/layout.module, line 436
The Layout module creates pages and wraps existing pages in layouts.

Code

function layout_route_handler($router_item) {
  // If a different delivery callback is specified, we're probably not returning
  // HTML and it definitely should not be wrapped in a layout. Call the default
  // route handler and return its response directly.
  if (!backdrop_is_html() || !empty($router_item['delivery_callback']) || $router_item['page_callback'] === 'layout_page_callback') {
    return menu_default_route_handler($router_item);
  }

  $selected_layout = layout_get_layout_by_path(NULL, $router_item);

  // Safety check that we don't show an admin layout to a user who cannot view
  // the admin theme. This may happen because the cached layout list does not
  // include a permissions check on the admin theme.
  if ($selected_layout->name === 'admin_default' && !user_access('view the administration theme')) {
    $selected_layout = layout_load('default');
  }

  // Special handling for 404 and 403 pages to render in admin theme. The
  // current path will be the 404/403 system path, and we need to check the
  // original path, which is stored in "destination" by
  // backdrop_deliver_html_page().
  if (in_array(backdrop_get_http_header('Status'), array('404 Not Found', '403 Forbidden')) && user_access('view the administration theme')) {
    if (isset($_GET['destination']) && path_is_admin($_GET['destination'])) {
      $selected_layout = layout_load('admin_default');
    }
  }

  if ($selected_layout) {
    // Render the layout.
    $renderer = layout_create_renderer($selected_layout->renderer_name, $selected_layout);
    if ($selected_layout->isDefault()) {
      $renderer->ensurePageContentBlock();
    }
    return $renderer->render();
  }

  // Fallback code if even the expected default layout cannot be found.
  return menu_default_route_handler($router_item);
}