function themekey_custom_theme in ThemeKey 7.3
Same name and namespace in other branches
- 7 themekey.module \themekey_custom_theme()
- 7.2 themekey.module \themekey_custom_theme()
Implements hook_custom_theme().
This is where all of ThemeKey's magic happens. ThemeKey detects if any Theme Switching Rule matches the current request and returns a custom theme.
7 string references to 'themekey_custom_theme'
- themekey_compat_dummy2theme in ./
themekey_compat.module - This function implements the interface of a ThemeKey mapping function but doesn't set a ThemeKey property's value. It sets the Drupal static themekey_custom_theme which will cause ThemeKey to use this theme.
- themekey_debug_init in ./
themekey_debug.module - Implements hook_init().
- themekey_match_condition in ./
themekey_base.inc - Detects if a ThemeKey rule matches to the current page request.
- themekey_ui_author2theme in ./
themekey_ui.module - This function implements the interface of a ThemeKey mapping function but doesn't set a ThemeKey property's value. It sets the Drupal static themekey_custom_theme which will cause ThemeKey to use this theme.
- themekey_ui_nid2theme in ./
themekey_ui.module - This function implements the interface of a ThemeKey mapping function, but doesn't set a ThemeKey property's value. It sets the Drupal static themekey_custom_theme which will cause ThemeKey to use this theme.
File
- ./
themekey.module, line 144 - ThemeKey is designed as a generic theme-switching module.
Code
function themekey_custom_theme() {
$custom_theme =& drupal_static('themekey_custom_theme', '');
if (themekey_is_active()) {
// If ThemeKey is active, themekey_is_active() already included themekey_base.inc.
$custom_theme_called =& drupal_static('themekey_custom_theme_called', FALSE);
$custom_theme_called = TRUE;
if (variable_get('themekey_ajax_base_page_theme', 1)) {
$custom_theme = themekey_ajax_base_page_theme();
}
if (!$custom_theme) {
$theme_candidate = NULL;
// A static rule might set $custom_theme during themekey_match_rules()
$result = themekey_match_rules();
if (is_array($result)) {
$theme_candidate = $result['theme'];
}
if (!$custom_theme && variable_get('themekey_debug_trace_rule_switching', FALSE)) {
themekey_set_debug_message('Theme candidate after rule matching: %theme_candidate', array(
'%theme_candidate' => $theme_candidate ? $theme_candidate : 'n/a',
));
themekey_set_debug_message('Theme stored in session: %theme', array(
'%theme' => !empty($_SESSION['themekey_theme']) ? $_SESSION['themekey_theme'] : 'n/a',
));
}
$used_session_theme = FALSE;
// If no theme has been triggered but a theme
// is in the user's session, use that theme.
if (!$theme_candidate && !empty($_SESSION['themekey_theme']) && (!$custom_theme || $custom_theme == variable_get('theme_default', 'bartik'))) {
$theme_candidate = $_SESSION['themekey_theme'];
$used_session_theme = TRUE;
if (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
themekey_set_debug_message('No rule triggered a different theme. Reusing last theme from user\'s session: %custom_theme', array(
'%custom_theme' => $theme_candidate,
));
}
}
// We have a theme, apply it
if (!empty($theme_candidate) && $theme_candidate != 'default' || !empty($custom_theme) && $custom_theme != 'default') {
if (!empty($theme_candidate) && $theme_candidate != 'default') {
$custom_theme = $theme_candidate;
}
if (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
themekey_set_debug_message('Switching theme to %custom_theme.', array(
'%custom_theme' => $custom_theme,
));
}
if (user_is_logged_in() && variable_get('themekey_theme_maintain', 0) || !user_is_logged_in() && variable_get('themekey_theme_maintain_anonymous', 0)) {
$_SESSION['themekey_theme'] = $custom_theme;
if (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
themekey_set_debug_message('Storing theme in session: %theme', array(
'%theme' => $custom_theme,
));
}
}
elseif (!empty($_SESSION['themekey_theme'])) {
unset($_SESSION['themekey_theme']);
if (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
themekey_set_debug_message('Removed theme from session.');
}
}
}
elseif (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
if ($custom_theme) {
// Static rules set $theme_candidate to 'default' and $custom_theme directly.
themekey_set_debug_message('$custom_theme has been set to %custom_theme during rule matching.', array(
'%custom_theme' => $custom_theme,
));
}
else {
themekey_set_debug_message('Using default theme.');
}
}
if ($custom_theme && !$used_session_theme) {
$custom_theme_not_altered = $custom_theme;
drupal_alter('themekey_custom_theme', $custom_theme, $result['rules_matched']);
if ($custom_theme_not_altered != $custom_theme) {
themekey_set_debug_message('%custom_theme_not_altered has been altered to %custom_theme.', array(
'custom_theme_not_altered' => $custom_theme_not_altered,
'%custom_theme' => $custom_theme,
));
}
if (!themekey_check_theme_enabled($custom_theme)) {
$custom_theme = $custom_theme_not_altered;
themekey_set_debug_message('%custom_theme is not enabled. Fall back to %custom_theme_not_altered.', array(
'%custom_theme' => $custom_theme,
'custom_theme_not_altered' => $custom_theme_not_altered,
));
}
}
}
elseif (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
themekey_set_debug_message('Skipped evaluation of rule chain because a static custom theme has been selected: %custom_theme', array(
'%custom_theme' => $custom_theme,
));
}
}
elseif (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
if (strpos($_GET['q'], 'admin/structure/block/demo') === 0) {
themekey_set_debug_message('Rule checking disabled on block demo.');
}
}
return $custom_theme;
}