diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-01-30 03:38:22 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-01-30 03:38:22 +0000 |
commit | 196aaa7d51b5ea9ac6422b93937b9070d5832272 (patch) | |
tree | eb947ef65e621185ee910f1878d2e580f4c6efc4 /includes | |
parent | 12ed4706557d978b0f43c3b8ab8cf454ebb590ac (diff) | |
download | brdo-196aaa7d51b5ea9ac6422b93937b9070d5832272.tar.gz brdo-196aaa7d51b5ea9ac6422b93937b9070d5832272.tar.bz2 |
#553944 follow-up by David_Rothstein: Allow modules to override per-page custom themes.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/menu.inc | 24 | ||||
-rw-r--r-- | includes/theme.inc | 26 |
2 files changed, 40 insertions, 10 deletions
diff --git a/includes/menu.inc b/includes/menu.inc index 3bb996243..5362aafd9 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -1505,8 +1505,8 @@ function menu_get_active_help() { * * @param $initialize * This parameter should only be used internally; it is set to TRUE in order - * to force the custom theme to be initialized from the menu router item for - * the current page. + * to force the custom theme to be initialized for the current page request. + * * @return * The machine-readable name of the custom theme, if there is one. * @@ -1517,9 +1517,23 @@ function menu_get_custom_theme($initialize = FALSE) { // Skip this if the site is offline or being installed or updated, since the // menu system may not be correctly initialized then. if ($initialize && !_menu_site_is_offline(TRUE) && (!defined('MAINTENANCE_MODE') || (MAINTENANCE_MODE != 'update' && MAINTENANCE_MODE != 'install'))) { - $router_item = menu_get_item(); - if (!empty($router_item['access']) && !empty($router_item['theme_callback']) && function_exists($router_item['theme_callback'])) { - $custom_theme = call_user_func_array($router_item['theme_callback'], $router_item['theme_arguments']); + // First allow modules to dynamically set a custom theme for the current + // page. Since we can only have one, the last module to return a valid + // theme takes precedence. + $custom_themes = array_filter(module_invoke_all('custom_theme'), 'drupal_theme_access'); + if (!empty($custom_themes)) { + $custom_theme = array_pop($custom_themes); + } + // Otherwise, execute the theme callback function for the current page, if + // there is one, in order to determine the custom theme to set. + if (!isset($custom_theme)) { + $router_item = menu_get_item(); + if (!empty($router_item['access']) && !empty($router_item['theme_callback']) && function_exists($router_item['theme_callback'])) { + $theme_name = call_user_func_array($router_item['theme_callback'], $router_item['theme_arguments']); + if (drupal_theme_access($theme_name)) { + $custom_theme = $theme_name; + } + } } } return $custom_theme; diff --git a/includes/theme.inc b/includes/theme.inc index afab19a22..eeb7a5faf 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -41,12 +41,28 @@ define('MARK_UPDATED', 2); * Determines if a theme is available to use. * * @param $theme - * An object representing the theme to check. + * Either the name of a theme or a full theme object. + * * @return * Boolean TRUE if the theme is enabled or is the site administration theme; * FALSE otherwise. */ function drupal_theme_access($theme) { + if (is_object($theme)) { + return _drupal_theme_access($theme); + } + else { + $themes = list_themes(); + return isset($themes[$theme]) && _drupal_theme_access($themes[$theme]); + } +} + +/** + * Helper function for determining access to a theme. + * + * @see drupal_theme_access() + */ +function _drupal_theme_access($theme) { $admin_theme = variable_get('admin_theme'); return !empty($theme->status) || ($admin_theme && $theme->name == $admin_theme); } @@ -67,12 +83,12 @@ function drupal_theme_initialize() { // Only select the user selected theme if it is available in the // list of themes that can be accessed. - $theme = !empty($user->theme) && isset($themes[$user->theme]) && drupal_theme_access($themes[$user->theme]) ? $user->theme : variable_get('theme_default', 'garland'); + $theme = !empty($user->theme) && drupal_theme_access($user->theme) ? $user->theme : variable_get('theme_default', 'garland'); - // Allow modules to override the present theme... only select custom theme - // if it is available in the list of themes that can be accessed. + // Allow modules to override the theme. Validation has already been performed + // inside menu_get_custom_theme(), so we do not need to check it again here. $custom_theme = menu_get_custom_theme(); - $theme = $custom_theme && isset($themes[$custom_theme]) && drupal_theme_access($themes[$custom_theme]) ? $custom_theme : $theme; + $theme = !empty($custom_theme) ? $custom_theme : $theme; // Store the identifier for retrieving theme settings with. $theme_key = $theme; |