1 menu.inc menu_execute_active_handler($path = NULL, $deliver = TRUE, $route_handler = NULL)

Execute the page callback associated with the current path.

Parameters

$path: The Backdrop path whose handler is to be be executed. If set to NULL, then the current path is used.

$deliver: (optional) A boolean to indicate whether the content should be sent to the browser using the appropriate delivery callback (TRUE) or whether to return the result to the caller (FALSE).

$route_handler: A callback function name to handle the content at this particular path. If left empty, the default route handler will be used. In most installations of Backdrop, the Layout module will provide the route handler, wrapping HTML pages in a layout.

Return value

string|NULL: If $deliver is FALSE, then the string result of the current active menu item will be returned. If $deliver is TRUE, no result will be returned; it will be printed directly to the page.

Related topics

File

core/includes/menu.inc, line 516
API for the Backdrop menu system.

Code

function menu_execute_active_handler($path = NULL, $deliver = TRUE, $route_handler = NULL) {
  $site_config = config('system.core');

  // Check if site is offline.
  $site_status = _menu_site_status($path, TRUE);

  // If online, check access to the page and call the menu handler.
  if ($site_status == MENU_SITE_ONLINE) {
    if ($router_item = menu_get_item($path)) {
      if ($router_item['access']) {
        // In most cases, Layout module will provide the route handler if
        // it is enabled. See layout_route_handler().
        if (empty($route_handler)) {
          $route_handler = $site_config->get('menu_route_handler');
        }
        if (empty($route_handler) || !function_exists($route_handler)) {
          $route_handler = 'menu_default_route_handler';
        }
        $page_callback_result = $route_handler($router_item);
      }
      else {
        $page_callback_result = MENU_ACCESS_DENIED;
      }
    }
    else {
      $page_callback_result = MENU_NOT_FOUND;
    }
  }
  // Offline pages are not cached in the database but have a Cache-Control
  // header to allow reverse proxies to serve offline hits instead of Backdrop.
  elseif ($site_status == MENU_SITE_OFFLINE) {
    $page_cache_enabled = (bool) $site_config->get('page_cache_maximum_age');
    $maintenance_max_age = $site_config->get('maintenance_page_maximum_age');
    if ($page_cache_enabled && $maintenance_max_age) {
      backdrop_add_http_header('Cache-Control', 'public; max-age: ' . $maintenance_max_age);
    }
    backdrop_page_is_cacheable(FALSE);
    $page_callback_result = MENU_SITE_OFFLINE;
  }
  // Any other statuses that may have been set in hook_menu_site_status_alter().
  else {
    $page_callback_result = $site_status;
  }

  // Deliver the result of the page callback to the browser, or if requested,
  // return it raw, so calling code can do more processing.
  if ($deliver && !is_null($page_callback_result)) {
    $default_delivery_callback = (isset($router_item) && $router_item) ? $router_item['delivery_callback'] : NULL;
    backdrop_deliver_page($page_callback_result, $default_delivery_callback);
    return NULL;
  }
  else {
    return $page_callback_result;
  }
}