Commit 249d9eae authored by catch's avatar catch

Issue #1213536 by David_Rothstein, sun, effulgentsia, Yorirou: Fixed...

Issue #1213536 by David_Rothstein, sun, effulgentsia, Yorirou: Fixed Non-resettable theme_get_registry() cache causes problems for non-interactive installations.
parent 3c7a609b
......@@ -452,6 +452,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();
// Allow modules to react prior to the installation of a module.
module_invoke_all('modules_preinstall', array($module));
......@@ -574,6 +576,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();
}
}
......
......@@ -237,7 +237,7 @@ function _drupal_theme_initialize($theme, $base_theme = array(), $registry_callb
/**
* Get the theme registry.
*
* @param $complete
* @param bool $complete
* Optional boolean to indicate whether to return the complete theme registry
* array or an instance of the ThemeRegistry class. If TRUE, the complete
* theme registry array will be returned. This is useful if you want to
......@@ -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()->deletePrefix('theme_registry');
}
......@@ -943,8 +957,6 @@ function drupal_find_base_themes($themes, $key, $used_keys = array()) {
* @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().
......@@ -952,10 +964,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.
......
......@@ -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;
}
......@@ -142,3 +145,10 @@ function theme_test_preprocess_html(&$variables) {
$variables['html_attributes_array']['theme_test_html_attribute'] = 'theme test html attribute value';
$variables['body_attributes_array']['theme_test_body_attribute'] = 'theme test body attribute value';
}
/**
* Theme function for testing theme('theme_test_foo').
*/
function theme_theme_test_foo($variables) {
return $variables['foo'];
}
......@@ -154,6 +154,19 @@ class ThemeUnitTest extends DrupalWebTestCase {
$this->assertNotEqual(theme_get_setting('subtheme_override', 'test_basetheme'), theme_get_setting('subtheme_override', 'test_subtheme'), t('Base theme\'s default settings values can be overridden by subtheme.'));
$this->assertIdentical(theme_get_setting('basetheme_only', 'test_subtheme'), 'base theme value', t('Base theme\'s default settings values are inherited by subtheme.'));
}
/**
* 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.');
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment