diff --git a/includes/module.inc b/includes/module.inc index 77e35b7..500bc5e 100644 --- a/includes/module.inc +++ b/includes/module.inc @@ -425,6 +425,8 @@ function module_enable($module_list, $enable_dependencies = TRUE) { registry_update(); // Refresh the schema to include it. drupal_get_schema(NULL, TRUE); + // Update the theme registry to include it. + drupal_theme_rebuild(); // Clear entity cache. entity_info_cache_clear(); @@ -546,6 +548,8 @@ function module_disable($module_list, $disable_dependents = TRUE) { // Update the registry to remove the newly-disabled module. registry_update(); _system_update_bootstrap_status(); + // Update the theme registry to remove the newly-disabled module. + drupal_theme_rebuild(); } // If there remains no more node_access module, rebuilding will be diff --git a/includes/theme.inc b/includes/theme.inc index 0712f87..53d7746 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -252,7 +252,20 @@ function _drupal_theme_initialize($theme, $base_theme = array(), $registry_callb * class. */ function theme_get_registry($complete = TRUE) { - static $theme_registry = array(); + // Use the advanced drupal_static() pattern, since this is called very often. + static $drupal_static_fast; + if (!isset($drupal_static_fast)) { + $drupal_static_fast['registry'] = &drupal_static('theme_get_registry'); + } + $theme_registry = &$drupal_static_fast['registry']; + + // Initialize the theme, if this is called early in the bootstrap, or after + // static variables have been reset. + if (!is_array($theme_registry)) { + drupal_theme_initialize(); + $theme_registry = array(); + } + $key = (int) $complete; if (!isset($theme_registry[$key])) { @@ -335,6 +348,7 @@ function _theme_save_registry($theme, $registry) { * to add more theme hooks. */ function drupal_theme_rebuild() { + drupal_static_reset('theme_get_registry'); cache_clear_all('theme_registry', 'cache', TRUE); } @@ -899,8 +913,6 @@ function list_themes($refresh = FALSE) { * @see themeable */ function theme($hook, $variables = array()) { - static $hooks = NULL; - // If called before all modules are loaded, we do not necessarily have a full // theme registry to work with, and therefore cannot process the theme // request properly. See also _theme_load_registry(). @@ -908,10 +920,7 @@ function theme($hook, $variables = array()) { throw new Exception(t('theme() may not be called until all modules are loaded.')); } - if (!isset($hooks)) { - drupal_theme_initialize(); - $hooks = theme_get_registry(FALSE); - } + $hooks = theme_get_registry(FALSE); // If an array of hook candidates were passed, use the first one that has an // implementation. diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php index 42bab12..251c5c1 100644 --- a/modules/simpletest/drupal_web_test_case.php +++ b/modules/simpletest/drupal_web_test_case.php @@ -1271,6 +1271,10 @@ class DrupalWebTestCase extends DrupalTestCase { ->condition('test_id', $this->testId) ->execute(); + // Reset all statics and variables to perform tests in a clean environment. + $conf = array(); + drupal_static_reset(); + // Clone the current connection and replace the current prefix. $connection_info = Database::getConnectionInfo('default'); Database::renameConnection('default', 'simpletest_original_default'); @@ -1318,10 +1322,6 @@ class DrupalWebTestCase extends DrupalTestCase { ini_set('log_errors', 1); ini_set('error_log', $public_files_directory . '/error.log'); - // Reset all statics and variables to perform tests in a clean environment. - $conf = array(); - drupal_static_reset(); - // Set the test information for use in other parts of Drupal. $test_info = &$GLOBALS['drupal_test_info']; $test_info['test_run_id'] = $this->databasePrefix; diff --git a/modules/simpletest/tests/theme.test b/modules/simpletest/tests/theme.test index 85f67b4..3afee3d 100644 --- a/modules/simpletest/tests/theme.test +++ b/modules/simpletest/tests/theme.test @@ -111,6 +111,19 @@ class ThemeTestCase extends DrupalWebTestCase { $this->drupalGet('theme-test/suggestion'); variable_set('preprocess_css', 0); } + + /** + * Ensures the theme registry is rebuilt when modules are disabled/enabled. + */ + function testRegistryRebuild() { + $this->assertIdentical(theme('theme_test_foo', array('foo' => 'a')), 'a', 'The theme registry contains theme_test_foo.'); + + module_disable(array('theme_test'), FALSE); + $this->assertIdentical(theme('theme_test_foo', array('foo' => 'b')), '', 'The theme registry does not contain theme_test_foo, because the module is disabled.'); + + module_enable(array('theme_test'), FALSE); + $this->assertIdentical(theme('theme_test_foo', array('foo' => 'c')), 'c', 'The theme registry contains theme_test_foo again after re-enabling the module.'); + } } /** diff --git a/modules/simpletest/tests/theme_test.module b/modules/simpletest/tests/theme_test.module index cce7b80..a9bd2ad 100644 --- a/modules/simpletest/tests/theme_test.module +++ b/modules/simpletest/tests/theme_test.module @@ -14,6 +14,9 @@ function theme_test_theme($existing, $type, $theme, $path) { $items['theme_test_template_test_2'] = array( 'template' => 'theme_test.template_test', ); + $items['theme_test_foo'] = array( + 'variables' => array('foo' => NULL), + ); return $items; } @@ -120,3 +123,10 @@ function _theme_test_alter() { function _theme_test_suggestion() { return theme(array('theme_test__suggestion', 'theme_test'), array()); } + +/** + * Theme function for testing theme('theme_test_foo'). + */ +function theme_theme_test_foo($variables) { + return $variables['foo']; +}