diff --git a/includes/common.inc b/includes/common.inc index 9346e6a..5087617 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -5255,11 +5255,22 @@ function _drupal_bootstrap_full() { // - The theme can have hook_*_alter() implementations affect page building // (e.g., hook_form_alter(), hook_node_view_alter(), hook_page_alter()), // ahead of when rendering starts. - menu_set_custom_theme(); + $custom_theme = menu_set_custom_theme(); + // If the custom theme is set and the base theme is set and they differ, + // reset the theme. + global $theme; + if (!empty($custom_theme) && !empty($theme) && $custom_theme != $theme) { + drupal_static_reset('theme_get_registry'); + $drupal_static_fast['registry'] = &drupal_static('theme_get_registry'); + $drupal_static_fast['registry'] = array(); + drupal_static_reset('drupal_add_js'); + drupal_static_reset('drupal_add_css'); + unset($GLOBALS['theme']); + } // Initialize the theme with the final initialization flag, this ensures // that the theme is properly set even if it was initialized by calling // theme related function during bootstrap. - drupal_theme_initialize(TRUE); + drupal_theme_initialize(); module_invoke_all('init'); } } diff --git a/includes/menu.inc b/includes/menu.inc index 1fe5a64..60abab4 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -1777,7 +1777,7 @@ function menu_get_custom_theme($initialize = FALSE) { * Sets a custom theme for the current page, if there is one. */ function menu_set_custom_theme() { - menu_get_custom_theme(TRUE); + return menu_get_custom_theme(TRUE); } /** diff --git a/modules/simpletest/tests/custom_theme_boot_test.module b/modules/simpletest/tests/custom_theme_boot_test.module index d89402e..20c8a64 100644 --- a/modules/simpletest/tests/custom_theme_boot_test.module +++ b/modules/simpletest/tests/custom_theme_boot_test.module @@ -14,10 +14,10 @@ function custom_theme_boot_test_custom_theme() { // the theme handling isn't right this will lead to a broken theme registry // and / or the wrong theme load. $node = node_load(arg(1)); - if ($node->type == 'page') { + if ($node->type == 'page' && $node->promote) { return 'garland'; } - elseif ($node->type == 'article') { + elseif ($node->type == 'article' && $node->promote) { return 'seven'; } } diff --git a/modules/simpletest/tests/custom_theme_boot_test.test b/modules/simpletest/tests/custom_theme_boot_test.test index 67f1804..21e736f 100644 --- a/modules/simpletest/tests/custom_theme_boot_test.test +++ b/modules/simpletest/tests/custom_theme_boot_test.test @@ -41,6 +41,10 @@ class CustomThemeBootTestCase extends NodeWebTestCase { 'type' => 'page', 'promote' => 1, )); + $node3 = $this->drupalCreateNode(array( + 'type' => 'page', + 'promote' => 0, + )); $this->drupalLogin($this->admin_user); $this->drupalGet('admin/appearance'); @@ -56,13 +60,19 @@ class CustomThemeBootTestCase extends NodeWebTestCase { // custom_theme_boot_test.module. The implementation calls l() which again // end's up loading the theme. $this->drupalGet('node/' . $node1->nid); - $this->assertText('seven'); - $this->assertNoText('garland'); - $this->assertNoText('bartik'); + $this->assertText('themes/seven/style.css'); + $this->assertNoText('themes/garland/style.css'); + $this->assertNoText('themes/bartik/css/style.css'); $this->drupalGet('node/' . $node2->nid); - $this->assertText('garland'); - $this->assertNoText('seven'); - $this->assertNoText('bartik'); + $this->assertText('themes/garland/style.css'); + $this->assertNoText('themes/seven/style.css'); + $this->assertNoText('themes/bartik/css/style.css'); + + // This makes sure that the base theme still loads as well. + $this->drupalGet('node/' . $node3->nid); + $this->assertText('themes/bartik/css/style.css'); + $this->assertNoText('themes/garland/style.css'); + $this->assertNoText('themes/seven/style.css'); } }