function drupal_theme_initialize

Initializes the theme system by loading the theme.

10 calls to drupal_theme_initialize()
batch_process in drupal/core/includes/form.inc
Processes the batch.
block_page_build in drupal/core/modules/block/block.module
Implements hook_page_build().
DisplayPluginBase::rescanThemes in drupal/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php
Submit hook to clear Drupal's theme registry (thereby triggering a templates rescan).
LegacyRequestSubscriber::onKernelRequestLegacy in drupal/core/lib/Drupal/Core/EventSubscriber/LegacyRequestSubscriber.php
Initializes the rest of the legacy Drupal subsystems.
menu_test_theme_page_callback in drupal/core/modules/system/tests/modules/menu_test/menu_test.module
Page callback to use when testing the theme callback functionality.

... See full list

File

drupal/core/includes/theme.inc, line 84
The theme system, which controls the output of Drupal.

Code

function drupal_theme_initialize() {
  global $theme, $user, $theme_key;

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

  // Only select the user selected theme if it is available in the
  // list of themes that can be accessed.
  $theme = !empty($user->theme) && drupal_theme_access($user->theme) ? $user->theme : config('system.theme')
    ->get('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 = menu_get_custom_theme();
  $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_theme = array();
  $ancestor = $theme;
  while ($ancestor && isset($themes[$ancestor]->base_theme)) {
    $ancestor = $themes[$ancestor]->base_theme;
    $base_theme[] = $themes[$ancestor];
  }
  _drupal_theme_initialize($themes[$theme], array_reverse($base_theme));

  // Themes can have alter functions, so reset the drupal_alter() cache.
  drupal_static_reset('drupal_alter');
}