diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/module.inc | 27 | ||||
-rw-r--r-- | includes/theme.inc | 48 |
2 files changed, 73 insertions, 2 deletions
diff --git a/includes/module.inc b/includes/module.inc index 500bc5ebc..28bca2350 100644 --- a/includes/module.inc +++ b/includes/module.inc @@ -178,6 +178,33 @@ function system_list($type) { $lists['filepaths'][] = array('type' => $record->type, 'name' => $record->name, 'filepath' => $record->filename); } } + foreach ($lists['theme'] as $key => $theme) { + if (!empty($theme->info['base theme'])) { + // Make a list of the theme's base themes. + $lists['theme'][$key]->base_themes = drupal_find_base_themes($lists['theme'], $key); + // Don't proceed if there was a problem with the root base theme. + if (!current($lists['theme'][$key]->base_themes)) { + continue; + } + // Determine the root base theme. + $base_key = key($lists['theme'][$key]->base_themes); + // Add to the list of sub-themes for each of the theme's base themes. + foreach (array_keys($lists['theme'][$key]->base_themes) as $base_theme) { + $lists['theme'][$base_theme]->sub_themes[$key] = $lists['theme'][$key]->info['name']; + } + // Add the base theme's theme engine info. + $lists['theme'][$key]->info['engine'] = isset($lists['theme'][$base_key]->info['engine']) ? $lists['theme'][$base_key]->info['engine'] : 'theme'; + } + else { + // A plain theme is its own engine. + $base_key = $key; + if (!isset($lists['theme'][$key]->info['engine'])) { + $lists['theme'][$key]->info['engine'] = 'theme'; + } + } + // Set the theme engine prefix. + $lists['theme'][$key]->prefix = ($lists['theme'][$key]->info['engine'] == 'theme') ? $base_key : $lists['theme'][$key]->info['engine']; + } cache_set('system_list', $lists, 'cache_bootstrap'); } // To avoid a separate database lookup for the filepath, prime the diff --git a/includes/theme.inc b/includes/theme.inc index 5552b0109..25f89f92e 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -737,7 +737,7 @@ function _theme_build_registry($theme, $base_theme, $theme_engine) { * names of the themes and the values are objects having the following * properties: * - 'filename': The name of the .info file. - * - 'name': The name of the theme. + * - 'name': The machine name of the theme. * - 'status': 1 for enabled, 0 for disabled themes. * - 'info': The contents of the .info file. * - 'stylesheets': A two dimensional array, using the first key for the @@ -747,7 +747,10 @@ function _theme_build_registry($theme, $base_theme, $theme_engine) { * - 'scripts': An associative array of JavaScripts, using the filename as key * and the complete filepath as value. * - 'engine': The name of the theme engine. - * - 'base theme': The name of the base theme. + * - 'base_theme': The name of the base theme. + * - 'base_themes': An ordered array of all the base themes. If the first item + * is NULL, a base theme is missing for this theme. + * - 'sub_themes': An unordered array of sub-themes of this theme. */ function list_themes($refresh = FALSE) { $list = &drupal_static(__FUNCTION__, array()); @@ -804,6 +807,47 @@ function list_themes($refresh = FALSE) { } /** + * Find all the base themes for the specified theme. + * + * Themes can inherit templates and function implementations from earlier themes. + * + * @param $themes + * An array of available themes. + * @param $key + * The name of the theme whose base we are looking for. + * @param $used_keys + * A recursion parameter preventing endless loops. + * @return + * Returns an array of all of the theme's ancestors; the first element's value + * will be NULL if an error occurred. + */ +function drupal_find_base_themes($themes, $key, $used_keys = array()) { + $base_key = $themes[$key]->info['base theme']; + // Does the base theme exist? + if (!isset($themes[$base_key])) { + return array($base_key => NULL); + } + + $current_base_theme = array($base_key => $themes[$base_key]->info['name']); + + // Is the base theme itself a child of another theme? + if (isset($themes[$base_key]->info['base theme'])) { + // Do we already know the base themes of this theme? + if (isset($themes[$base_key]->base_themes)) { + return $themes[$base_key]->base_themes + $current_base_theme; + } + // Prevent loops. + if (!empty($used_keys[$base_key])) { + return array($base_key => NULL); + } + $used_keys[$base_key] = TRUE; + return drupal_find_base_themes($themes, $base_key, $used_keys) + $current_base_theme; + } + // If we get here, then this is our parent theme. + return $current_base_theme; +} + +/** * Generates themed output. * * All requests for themed output must go through this function. It examines |