role_theme_switcher.module in Role Theme Switcher 5.2
File
role_theme_switcher.module
View source
<?php
function role_theme_switcher_init() {
global $user, $custom_theme, $theme;
foreach ($user->roles as $key => $value) {
$role_name = str_replace(' ', '_', $value);
$role_theme = variable_get(strtolower($role_name) . '_theme', '');
$user->theme = $role_theme;
$custom_theme = $role_theme;
drupal_clear_css_cache();
}
}
function role_theme_switcher_menu($may_cache) {
if ($may_cache) {
$items[] = array(
'path' => 'admin/user/themes',
'type' => MENU_NORMAL_ITEM,
'title' => t('Role theme switcher'),
'description' => t('Settings for role theme switcher.'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'role_theme_switcher_admin_settings',
),
'access' => user_access('administer site configuration'),
);
}
return $items;
}
function role_theme_switcher_admin_settings() {
$roles = user_roles();
$themes = list_themes();
$list = array_merge(array(
t('Default'),
), array_keys($themes));
foreach ($roles as $id => $role) {
$role_name = str_replace(' ', '_', $role);
$form[strtolower($role_name) . '_theme'] = array(
'#type' => 'select',
'#title' => ucfirst(strtolower($role)),
'#options' => drupal_map_assoc($list),
'#default_value' => variable_get(strtolower($role_name) . '_theme', ''),
);
}
return system_settings_form($form);
}