You are here

shortcut_per_role.module in Shortcut per Role 7

Allows users to manage customizable lists of shortcut links.

File

shortcut_per_role.module
View source
<?php

/**
 * @file
 * Allows users to manage customizable lists of shortcut links.
 */

/**
 * Implements hook_permission().
 */
function shortcut_per_role_permission() {
  return array(
    'administer shortcut per role' => array(
      'title' => t('Administer Shortcuts per Role'),
    ),
  );
}

/**
 * Implement hook_help().
 */
function shortcut_per_role_help($path, $arg) {
  switch ($path) {
    case 'admin/help#shortcut_per_role':
      $output = '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Assign the default shortcut set per role') . '</p>';
      return $output;
  }
}

/**
 * Implements hook_menu().
 */
function shortcut_per_role_menu() {
  $items['admin/config/user-interface/shortcut-per-role'] = array(
    'title' => 'Shortcuts Per Role',
    'description' => 'Add and modify shortcut sets per role',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'shortcut_per_role_admin_form',
    ),
    'access arguments' => array(
      'administer shortcut per role',
    ),
    'file' => 'shortcut_per_role.admin.inc',
  );
  return $items;
}

/**
 * Implements hook_shortcut_default_set()
 */
function shortcut_per_role_shortcut_default_set($account) {

  //determine the highest rid of user & assign the shortcut set...
  $query = db_select('role', 'r')
    ->condition('rid', array_keys($account->roles), 'IN')
    ->fields('r', array(
    'rid',
  ))
    ->orderBy('weight', 'DESC');
  $h_rid = $query
    ->execute()
    ->fetchField();
  $ss_per_role = variable_get('shortcut_per_role', array());
  $ss = array_key_exists($h_rid, $ss_per_role) ? $ss_per_role[$h_rid] : 'shortcut_set_1';
  return $ss;
}

/**
 * Implements hook_user_role_delete()
 */
function shortcut_per_role_user_role_delete($role) {
  $rid = $role->rid;
  $ss_per_role = variable_get('shortcut_per_role', array());
  if (array_key_exists($rid, $ss_per_role)) {
    unset($ss_per_role[$rid]);
  }
  variable_set('shortcut_per_role', $ss_per_role);
}