1 theme.inc _theme_build_registry($theme, $base_themes, $theme_engine)

Builds the theme registry cache.

Parameters

$theme: The loaded $theme object as returned by list_themes().

array $base_themes: An array of loaded $theme objects representing the ancestor themes in oldest first order.

string $theme_engine: The name of the theme engine.

Return value

array: The completely built theme registry.

File

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

Code

function _theme_build_registry($theme, $base_themes, $theme_engine) {
  $cache = array();
  $modules_loaded = module_load_all(NULL);

  // First, process the theme hooks advertised by modules. This will
  // serve as the basic registry. Since the list of enabled modules is the same
  // regardless of the theme used, this is cached in its own entry to save
  // building it for every theme.
  if ($modules_loaded && $cached = cache()->get('theme_registry:build:modules')) {
    $cache = $cached->data;
  }
  else {
    foreach (module_implements('theme') as $module) {
      _theme_process_registry($cache, $module, 'module', $module, backdrop_get_path('module', $module));
    }
    // Only cache this registry if all modules are loaded.
    if ($modules_loaded) {
      cache()->set('theme_registry:build:modules', $cache);
    }
  }

  // Process each base theme.
  foreach ($base_themes as $base) {
    // If the base theme uses a theme engine, process its hooks.
    $base_path = dirname($base->filename);
    if ($theme_engine) {
      _theme_process_registry($cache, $theme_engine, 'base_theme_engine', $base->name, $base_path);
    }
    _theme_process_registry($cache, $base->name, 'base_theme', $base->name, $base_path);
  }

  // And then the same thing, but for the theme.
  if ($theme_engine) {
    _theme_process_registry($cache, $theme_engine, 'theme_engine', $theme->name, dirname($theme->filename));
  }

  // Finally, hooks provided by the theme itself.
  _theme_process_registry($cache, $theme->name, 'theme', $theme->name, dirname($theme->filename));

  // Let modules alter the registry.
  backdrop_alter('theme_registry', $cache);

  // Optimize the registry to not have empty arrays for functions.
  foreach ($cache as $hook => $info) {
    if (empty($info['preprocess functions'])) {
      unset($cache[$hook]['preprocess functions']);
    }
  }
  return $cache;
}