summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-08-22 12:46:21 +0000
committerDries Buytaert <dries@buytaert.net>2010-08-22 12:46:21 +0000
commitb0894ceaa74c01444856910fd87dfc992542eb85 (patch)
tree5dbbd695351e7344279e27b32454beede85b53e2 /includes
parentee691c593adfaf4c8046cf6ee2bc9796a28a1448 (diff)
downloadbrdo-b0894ceaa74c01444856910fd87dfc992542eb85.tar.gz
brdo-b0894ceaa74c01444856910fd87dfc992542eb85.tar.bz2
- Patch #812016 by effulgentsia, chx, redndahead, Damien Tournoud: themes cannot always participate in drupal_alter().
Diffstat (limited to 'includes')
-rw-r--r--includes/common.inc16
-rw-r--r--includes/theme.inc39
-rw-r--r--includes/theme.maintenance.inc3
3 files changed, 33 insertions, 25 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 959675f8b..afb08eafd 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -4592,13 +4592,19 @@ function _drupal_bootstrap_full() {
// Initialize $_GET['q'] prior to invoking hook_init().
drupal_path_initialize();
- // Set a custom theme for the current page, if there is one. We need to run
- // this before invoking hook_init(), since any modules which initialize the
- // theme system will prevent a custom theme from being correctly set later.
- menu_set_custom_theme();
- // Let all modules take action before menu system handles the request
+
+ // Let all modules take action before the menu system handles the request.
// We do not want this while running update.php.
if (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update') {
+ // Prior to invoking hook_init(), initialize the theme (potentially a custom
+ // one for this page), so that:
+ // - Modules with hook_init() implementations that call theme() or
+ // theme_get_registry() don't initialize the incorrect theme.
+ // - 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();
+ drupal_theme_initialize();
module_invoke_all('init');
}
}
diff --git a/includes/theme.inc b/includes/theme.inc
index eb7111a47..a696117cf 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -221,8 +221,8 @@ function _drupal_theme_initialize($theme, $base_theme = array(), $registry_callb
}
}
- if (function_exists($registry_callback)) {
- $registry_callback($theme, $base_theme, $theme_engine);
+ if (isset($registry_callback)) {
+ _theme_registry_callback($registry_callback, array($theme, $base_theme, $theme_engine));
}
}
@@ -233,26 +233,30 @@ function _drupal_theme_initialize($theme, $base_theme = array(), $registry_callb
* The theme registry array if it has been stored in memory, NULL otherwise.
*/
function theme_get_registry() {
- return _theme_set_registry();
+ static $theme_registry = NULL;
+
+ if (!isset($theme_registry)) {
+ list($callback, $arguments) = _theme_registry_callback();
+ $theme_registry = call_user_func_array($callback, $arguments);
+ }
+
+ return $theme_registry;
}
/**
- * Store the theme registry in memory.
- *
- * @param $registry
- * A registry array as returned by _theme_build_registry()
+ * Set the callback that will be used by theme_get_registry() to fetch the registry.
*
- * @return
- * The theme registry array stored in memory
+ * @param $callback
+ * The name of the callback function.
+ * @param $arguments
+ * The arguments to pass to the function.
*/
-function _theme_set_registry($registry = NULL) {
- static $theme_registry = NULL;
-
- if (isset($registry)) {
- $theme_registry = $registry;
+function _theme_registry_callback($callback = NULL, array $arguments = array()) {
+ static $stored;
+ if (isset($callback)) {
+ $stored = array($callback, $arguments);
}
-
- return $theme_registry;
+ return $stored;
}
/**
@@ -271,7 +275,6 @@ function _theme_load_registry($theme, $base_theme = NULL, $theme_engine = NULL)
$cache = cache_get("theme_registry:$theme->name", 'cache');
if (isset($cache->data)) {
$registry = $cache->data;
- _theme_set_registry($registry);
}
else {
// If not, build one and cache it.
@@ -280,9 +283,9 @@ function _theme_load_registry($theme, $base_theme = NULL, $theme_engine = NULL)
// complete set of theme hooks.
if (module_load_all(NULL)) {
_theme_save_registry($theme, $registry);
- _theme_set_registry($registry);
}
}
+ return $registry;
}
/**
diff --git a/includes/theme.maintenance.inc b/includes/theme.maintenance.inc
index 927499a8f..419d300f1 100644
--- a/includes/theme.maintenance.inc
+++ b/includes/theme.maintenance.inc
@@ -88,8 +88,7 @@ function _drupal_maintenance_theme() {
* This builds the registry when the site needs to bypass any database calls.
*/
function _theme_load_offline_registry($theme, $base_theme = NULL, $theme_engine = NULL) {
- $registry = _theme_build_registry($theme, $base_theme, $theme_engine);
- _theme_set_registry($registry);
+ return _theme_build_registry($theme, $base_theme, $theme_engine);
}
/**