1 theme.inc backdrop_theme_initialize()

Initializes the theme system by loading the theme.

File

core/includes/theme.inc, line 85
The theme system, which controls the output of Backdrop.

Code

function backdrop_theme_initialize() {
  global $theme, $theme_key;

  // If $theme is already set, assume the others are set, too, and do nothing
  if (isset($theme)) {
    return;
  }

  backdrop_bootstrap(BACKDROP_BOOTSTRAP_DATABASE);
  $themes = list_themes();

  // Load the default theme.
  $theme = config_get('system.core', 'theme_default');

  // Allow modules to override the theme. Validation has already been performed
  // inside menu_get_custom_theme(), so we do not need to check it again here.
  $custom_theme = function_exists('menu_get_custom_theme') ? menu_get_custom_theme() : NULL;
  $theme = !empty($custom_theme) ? $custom_theme : $theme;

  // Store the identifier for retrieving theme settings with.
  $theme_key = $theme;

  // Find all our ancestor themes and put them in an array.
  $base_themes = array();
  $ancestor = $theme;
  while ($ancestor && isset($themes[$ancestor]->base_theme)) {
    $ancestor = $themes[$ancestor]->base_theme;
    $base_themes[] = $themes[$ancestor];
  }
  _backdrop_theme_initialize($themes[$theme], array_reverse($base_themes));

  // Themes can have alter functions, so reset the backdrop_alter() cache.
  backdrop_static_reset('backdrop_alter');

  // Provide the page with information about the theme that's used, so that a
  // later Ajax request can be rendered using the same theme.
  // @see ajax_base_page_theme()
  $setting['ajaxPageState'] = array(
    'theme' => $theme_key,
    'theme_token' => backdrop_get_token($theme_key),
  );
  backdrop_add_js($setting, 'setting');
}