You are here

role_theme_switcher.module in Role Theme Switcher 5.2

File

role_theme_switcher.module
View source
<?php

/** 
 * Implemntation of hook_init().
 */
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', '');

    // Change active theme in user object
    $user->theme = $role_theme;

    // Also change the active theme globally
    $custom_theme = $role_theme;
    drupal_clear_css_cache();
  }
}

/**
 * Implementation of hook_menu().
 */
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;
}

/**
 * Implemntation of hook_settings().
 */
function role_theme_switcher_admin_settings() {
  $roles = user_roles();

  // Get all enabled themes
  $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);
}

Functions

Namesort descending Description
role_theme_switcher_admin_settings Implemntation of hook_settings().
role_theme_switcher_init Implemntation of hook_init().
role_theme_switcher_menu Implementation of hook_menu().