diff --git a/includes/theme.inc b/includes/theme.inc index 9e15f21e62452ea6e53fe70b126175a2beb7a592..e7fec486d5a619d1b5e4fa0be4cbb092574808b0 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -54,18 +54,8 @@ function init_theme() { $base_theme = array(); $ancestor = $theme; while ($ancestor && isset($themes[$ancestor]->base_theme)) { - if (isset($themes[$themes[$ancestor]->base_theme])) { - $base_theme[] = $new_base_theme = $themes[$themes[$ancestor]->base_theme]; - // stop if this is final ancestor. - if (!isset($new_base_theme->base_theme)) { - break; - } - $ancestor = $new_base_theme->base_theme; - } - // stop if ancestor didn't exist. - else { - break; - } + $base_theme[] = $new_base_theme = $themes[$themes[$ancestor]->base_theme]; + $ancestor = $themes[$ancestor]->base_theme; } _init_theme($themes[$theme], array_reverse($base_theme)); } @@ -100,21 +90,62 @@ function _init_theme($theme, $base_theme = array()) { $theme_path = dirname($theme->filename); + // Prepare stylesheets from this theme as well as all ancestor themes. + // We work it this way so that we can have child themes override parent + // theme stylesheets easily. + $final_stylesheets = array(); + + // Grab stylesheets from base theme + foreach ($base_theme as $base) { + if (!empty($base->stylesheets)) { + foreach ($base->stylesheets as $media => $stylesheets) { + foreach ($stylesheets as $name => $stylesheet) { + $final_stylesheets[$media][$name] = $stylesheet; + } + } + } + } + // Add stylesheets used by this theme. if (!empty($theme->stylesheets)) { foreach ($theme->stylesheets as $media => $stylesheets) { - foreach ($stylesheets as $stylesheet) { - drupal_add_css($stylesheet, 'theme', $media); + foreach ($stylesheets as $name => $stylesheet) { + $final_stylesheets[$media][$name] = $stylesheet; } } } + + // And now add the stylesheets properly + foreach ($final_stylesheets as $media => $stylesheets) { + foreach ($stylesheets as $stylesheet) { + drupal_add_css($stylesheet, 'theme', $media); + } + } + + // Do basically the same as the above for scripts + $final_scripts = array(); + + // Grab scripts from base theme + foreach ($base_theme as $base) { + if (!empty($base->scripts)) { + foreach ($base->scripts as $name => $script) { + $final_scripts[$name] = $script; + } + } + } + // Add scripts used by this theme. if (!empty($theme->scripts)) { - foreach ($theme->scripts as $script) { - drupal_add_js($script, 'theme'); + foreach ($theme->scripts as $name => $script) { + $final_scripts[$name] = $script; } } + // Add scripts used by this theme. + foreach ($final_scripts as $script) { + drupal_add_js($script, 'theme'); + } + $theme_engine = NULL; // Initialize the theme. diff --git a/modules/system/system.admin.inc b/modules/system/system.admin.inc index 09297e1c4416ec8f98fa74fd564982f4fe7e2634..6ed8e62460f7b697c8c4978c14aa07a8bb076d23 100644 --- a/modules/system/system.admin.inc +++ b/modules/system/system.admin.inc @@ -281,6 +281,7 @@ function system_themes_form_submit($form, &$form_state) { list_themes(TRUE); menu_rebuild(); + drupal_rebuild_theme_registry(); drupal_set_message(t('The configuration options have been saved.')); $form_state['redirect'] = 'admin/build/themes'; diff --git a/modules/system/system.module b/modules/system/system.module index 65d6219b847c1076f3e8303932689d0441b360c5..8827857e8856e7657fc6767809e4417c683366f4 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -742,28 +742,6 @@ function system_theme_data() { $themes[$key]->prefix = $key; } } - // Add any stylesheets from the base theme, unless the names match in which case - // the sub-theme wins. Note that we slip the base theme's stylesheets in at the - // beginning of the array so that they get added to the page in the correct order. - foreach ($themes[$base_key]->info['stylesheets'] as $media => $stylesheets) { - foreach ($stylesheets as $stylesheet => $path) { - if (!isset($themes[$key]->info['stylesheets'][$media][$stylesheet])) { - // We need to ensure the media array exists, or the array addition below doesn't work. - if (!isset($themes[$key]->info['stylesheets'][$media])) { - $themes[$key]->info['stylesheets'][$media] = array(); - } - $themes[$key]->info['stylesheets'][$media] = array($stylesheet => $path) + $themes[$key]->info['stylesheets'][$media]; - } - } - } - // Add any scripts from the base theme, unless the names match in which case - // the sub-theme wins. Note that we slip the base theme's scripts in at the - // beginning of the array so that they get added to the page in the correct order. - foreach ($themes[$base_key]->info['scripts'] as $script => $path) { - if (!isset($themes[$key]->info['scripts'][$script])) { - $themes[$key]->info['scripts'] = array($script => $path) + $themes[$key]->info['scripts']; - } - } } // Extract current files from database. @@ -798,7 +776,7 @@ function system_find_base_theme($themes, $key, $used_keys = array()) { // Is the base theme itself a child of another theme? if (isset($themes[$base_key]->info['base theme'])) { // Prevent loops. - if ($used_keys[$base_key]) { + if (!empty($used_keys[$base_key])) { return NULL; } $used_keys[$base_key] = TRUE;