#489762 by JohnAlbin: Add theme lineage information to .info file cache and fix several edge-case bugs.

merge-requests/26/head
Angie Byron 2009-08-03 06:06:23 +00:00
parent 0bd7fcbf38
commit 542c3522c0
2 changed files with 33 additions and 14 deletions

View File

@ -149,13 +149,19 @@ function system_themes_form() {
foreach ($themes as $theme) {
$screenshot = NULL;
$theme_key = $theme->name;
while ($theme_key) {
if (file_exists($themes[$theme_key]->info['screenshot'])) {
// Create a list which includes the current theme and all its base themes.
if (isset($themes[$theme->name]->base_themes)) {
$theme_keys = array_keys($themes[$theme->name]->base_themes) + array($theme->name);
}
else {
$theme_keys = array($theme->name);
}
// Look for a screenshot in the current theme or in its closest ancestor.
foreach (array_reverse($theme_keys) as $theme_key) {
if (isset($themes[$theme_key]) && file_exists($themes[$theme_key]->info['screenshot'])) {
$screenshot = $themes[$theme_key]->info['screenshot'];
break;
}
$theme_key = isset($themes[$theme_key]->info['base theme']) ? $themes[$theme_key]->info['base theme'] : NULL;
}
$screenshot = $screenshot ? theme('image', $screenshot, t('Screenshot for %theme theme', array('%theme' => $theme->info['name'])), '', array('class' => 'screenshot'), FALSE) : t('no screenshot');

View File

@ -1925,10 +1925,15 @@ function _system_get_theme_data() {
// Now that we've established all our master themes, go back and fill in
// data for subthemes.
foreach ($sub_themes as $key) {
$base_key = system_find_base_theme($themes, $key);
if (!$base_key) {
$themes[$key]->base_themes = system_find_base_themes($themes, $key);
// Don't proceed if there was a problem with the root base theme.
if (!current($themes[$key]->base_themes)) {
continue;
}
$base_key = key($themes[$key]->base_themes);
foreach (array_keys($themes[$key]->base_themes) as $base_theme) {
$themes[$base_theme]->sub_themes[$key] = $themes[$key]->info['name'];
}
// Copy the 'owner' and 'engine' over if the top level theme uses a
// theme engine.
if (isset($themes[$base_key]->owner)) {
@ -1964,8 +1969,9 @@ function system_get_theme_data() {
}
/**
* Recursive function to find the top level base theme. Themes can inherit
* templates and function implementations from earlier themes.
* 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.
@ -1974,26 +1980,33 @@ function system_get_theme_data() {
* @param $used_keys
* A recursion parameter preventing endless loops.
* @return
* Returns the top level parent that has no ancestor or returns NULL if there isn't a valid parent.
* Returns an array of all of the theme's ancestors; the first element's value
* will be NULL if an error occurred.
*/
function system_find_base_theme($themes, $key, $used_keys = array()) {
function system_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 NULL;
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 NULL;
return array($base_key => NULL);
}
$used_keys[$base_key] = TRUE;
return system_find_base_theme($themes, $base_key, $used_keys);
return system_find_base_themes($themes, $base_key, $used_keys) + $current_base_theme;
}
// If we get here, then this is our parent theme.
return $base_key;
return $current_base_theme;
}
/**