themekey_compat.module in ThemeKey 7
Same filename and directory in other branches
Integration of different theme switching modules into ThemeKey and it's theme switching rule chain.
@author Markus Kalkbrenner | Cocomore AG
File
themekey_compat.moduleView source
<?php
/**
* @file
* Integration of different theme switching modules into ThemeKey and it's theme switching rule chain.
* @see themekey.module
*
* @author Markus Kalkbrenner | Cocomore AG
* @see http://drupal.org/user/124705
*/
/**
* Implements hook_menu().
*/
function themekey_compat_menu() {
$items = array();
$items['admin/config/user-interface/themekey/settings/compat'] = array(
'title' => 'Compatibility',
'access callback' => 'user_access',
'access arguments' => array(
'administer themekey settings',
),
'file' => 'themekey_compat_admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'themekey_compat_settings_form',
),
'type' => MENU_LOCAL_TASK,
'weight' => 11,
);
return $items;
}
/**
* Implements hook_themekey_properties().
*
* Provides additional properties for the ThemeKey module:
* themekey_compat:module_MODULE_triggers_theme
*
* @return
* array of themekey properties
*/
function themekey_compat_themekey_properties() {
// Attributes for properties
$attributes = array();
// Mapping functions
$maps = array();
foreach (variable_get('themekey_compat_modules_enabled', array()) as $module) {
$attributes['themekey_compat:module_' . $module . '_triggers_theme'] = array(
'description' => t("The property, themekey_compat:module_' . {$module} . '_triggers_theme, could not be selected from the property drop-down. You get this static property by activating !link. Afterwards, you can move the property to any position in the rule chain. When done, it triggers the switch to the theme assigned to the current node using ThemeKey UI.", array(
'!link' => l(t('Show theme option in create/edit node forms'), 'admin/config/user-interface/themekey/settings/ui'),
)),
'page cache' => THEMEKEY_PAGECACHE_SUPPORTED,
'static' => TRUE,
);
$maps[] = array(
'src' => 'system:dummy',
'dst' => 'themekey_compat:module_' . $module . '_triggers_theme',
'callback' => 'themekey_compat_dummy2theme',
'args' => array(
'module' => $module,
),
);
}
return array(
'attributes' => $attributes,
'maps' => $maps,
);
}
/**
* 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.
*
* @param $dummy
* dummy
*
* @return
* string "static" if global custom theme has been set
* or NULL if no theme has been assigned to the node
*/
function themekey_compat_dummy2theme($dummy, $args) {
$custom_theme =& drupal_static('themekey_custom_theme', '');
$function = $args['module'] . '_custom_theme';
if (function_exists($function)) {
$custom_theme = $function();
if ($custom_theme && (!in_array($args['module'], variable_get('themekey_compat_modules_enabled', array())) || variable_get('theme_default', 'bartik') != $custom_theme)) {
if (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
themekey_set_debug_message('Theme set to %theme by module %module.', array(
'%theme' => $custom_theme,
'%module' => $args['module'],
));
}
return 'static';
}
}
return NULL;
}
/**
* Implements hook_modules_disabled().
*/
function themekey_compat_modules_disabled($modules) {
require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'themekey') . '/themekey_build.inc';
variable_set('themekey_compat_modules_enabled', array_diff(variable_get('themekey_compat_modules_enabled', array()), $modules));
foreach ($modules as $module) {
themekey_update_static_rule('themekey_compat:module_' . $module . '_triggers_theme', FALSE);
}
}
function themekey_compat_module_implements_alter(&$implementations, $hook) {
if ('custom_theme' == $hook) {
foreach (variable_get('themekey_compat_modules_enabled', array()) as $module) {
unset($implementations['$module']);
}
}
}
Functions
Name | Description |
---|---|
themekey_compat_dummy2theme | 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_compat_menu | Implements hook_menu(). |
themekey_compat_modules_disabled | Implements hook_modules_disabled(). |
themekey_compat_module_implements_alter | |
themekey_compat_themekey_properties | Implements hook_themekey_properties(). |