1 menu.inc menu_get_custom_theme($initialize = FALSE)

Gets the custom theme for the current page, if there is one.

Parameters

$initialize: This parameter should only be used internally; it is set to TRUE in order to force the custom theme to be initialized for the current page request.

Return value

The machine-readable name of the custom theme, if there is one.

See also

menu_set_custom_theme()

Related topics

File

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

Code

function menu_get_custom_theme($initialize = FALSE) {
  $custom_theme = &backdrop_static(__FUNCTION__);

  // Offline mode checking does not allow for module overrides of the theme.
  $offline_mode = (_menu_site_status() === MENU_SITE_OFFLINE || defined('MAINTENANCE_MODE'));
  if ($offline_mode) {
    $custom_theme = settings_get('maintenance_theme');
    if (empty($custom_theme)) {
      $custom_theme = config_get('system.core', 'maintenance_theme');
    }
    if (empty($custom_theme)) {
      $custom_theme = config_get('system.core', 'theme_default');
    }
  }
  elseif ($initialize) {
    // First allow modules to dynamically set a custom theme for the current
    // page. Since we can only have one, the last module to return a valid
    // theme takes precedence.
    $custom_themes = array_filter(module_invoke_all('custom_theme'), 'backdrop_theme_access');
    if (!empty($custom_themes)) {
      $custom_theme = array_pop($custom_themes);
    }
    // If there is a theme callback function for the current page, execute it.
    // If this returns a valid theme, it will override any theme that was set
    // by a hook_custom_theme() implementation above.
    $router_item = menu_get_item();
    if (!empty($router_item['access']) && !empty($router_item['theme_callback'])) {
      $theme_name = call_user_func_array($router_item['theme_callback'], $router_item['theme_arguments']);
      if (backdrop_theme_access($theme_name)) {
        $custom_theme = $theme_name;
      }
    }
  }
  return $custom_theme;
}