You are here

admin_menu_dropdown.module in Admin Menu Hider 6

Makes drupal administration menu able to be hidden or shown by pressing key combo

File

admin_menu_dropdown.module
View source
<?php

/**
 * @file
 * Makes drupal administration menu able to be hidden or shown by pressing key combo
 */

/**
 * Implementation of hook_init().
 */
function admin_menu_dropdown_init() {
  if (user_access('access administration menu')) {
    $css = variable_get('admin_menu_dropdown_hide', TRUE) ? 'admin_menu_dropdown.css' : 'admin_menu_dropdown_show.css';
    $js = variable_get('admin_menu_dropdown_hide', TRUE) ? "hidden = 1;" : "hidden = 0;";
    $js .= " visibilityCombo = '" . variable_get('admin_menu_dropdown_visibility_modifier', 'ctrl + alt');
    $js .= variable_get('admin_menu_dropdown_visibility_key', '') ? " + " . variable_get('admin_menu_dropdown_visibility_key', '') . "';" : "';";
    $js .= " disableCombo = '" . variable_get('admin_menu_dropdown_disable_modifier', 'ctrl + alt + shift');
    $js .= variable_get('admin_menu_dropdown_disable_key', '') ? " + " . variable_get('admin_menu_dropdown_disable_key', '') . "';" : "';";
    drupal_add_css(drupal_get_path('module', 'admin_menu_dropdown') . '/' . $css, 'module');
    drupal_add_js($js, 'inline');
    drupal_add_js(drupal_get_path('module', 'admin_menu_dropdown') . '/admin_menu_dropdown.js', 'module');
  }
}

/**
 * Implementation of hook_form_alter().
 */
function admin_menu_dropdown_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'admin_menu_theme_settings') {
    drupal_add_css(drupal_get_path('module', 'admin_menu_dropdown') . '/admin_menu_dropdown_settings.css', 'module');
    $form['buttons']['#weight'] = '1';
    $form['admin_menu_dropdown'] = array(
      '#type' => 'fieldset',
      '#title' => 'Administration Menu Dropdown',
      '#element_validate' => array(
        'admin_menu_dropdown_settings_validate',
      ),
    );
    $form['admin_menu_dropdown']['admin_menu_dropdown_visibility_modifier'] = array(
      '#type' => 'select',
      '#title' => t('Display modifier + key'),
      '#options' => admin_menu_dropdown_settings_combos('modifier'),
      '#default_value' => variable_get('admin_menu_dropdown_visibility_modifier', ''),
      '#prefix' => '<div class="inline-element">',
      '#suffix' => '</div>',
    );
    $form['admin_menu_dropdown']['admin_menu_dropdown_visibility_key'] = array(
      '#type' => 'select',
      '#options' => admin_menu_dropdown_settings_combos('key'),
      '#default_value' => variable_get('admin_menu_dropdown_visibility_key', ''),
      '#description' => t('Key combination to show/hide Administration Menu.'),
      '#prefix' => '<div class="inline-element"> + ',
      '#suffix' => '</div>',
    );
    $form['admin_menu_dropdown']['admin_menu_dropdown_disable_modifier'] = array(
      '#type' => 'select',
      '#title' => t('Disable modifier + key'),
      '#options' => admin_menu_dropdown_settings_combos('modifier'),
      '#default_value' => variable_get('admin_menu_dropdown_disable_modifier', 'ctrl + alt + shift'),
      '#prefix' => '<div class="inline-element">',
      '#suffix' => '</div>',
    );
    $form['admin_menu_dropdown']['admin_menu_dropdown_disable_key'] = array(
      '#type' => 'select',
      '#options' => admin_menu_dropdown_settings_combos('key'),
      '#default_value' => variable_get('admin_menu_dropdown_disable_key', ''),
      '#description' => t('Key combination to enable/disable hiding of Administration Menu.'),
      '#prefix' => '<div class="inline-element"> + ',
      '#suffix' => '</div>',
    );
    $form['admin_menu_dropdown']['admin_menu_dropdown_hide'] = array(
      '#type' => 'checkbox',
      '#title' => t('Hide admin menu by default'),
      '#default_value' => variable_get('admin_menu_dropdown_hide', TRUE),
      '#description' => t('If checked the Drupal Administration Menu is hidden by default'),
    );
  }
}
function admin_menu_dropdown_settings_validate($form, &$form_state) {
  if ($form_state['values']['admin_menu_dropdown_visibility_modifier'] == $form_state['values']['admin_menu_dropdown_disable_modifier'] && $form_state['values']['admin_menu_dropdown_visibility_key'] == $form_state['values']['admin_menu_dropdown_disable_key']) {
    form_set_error('', t('Each key combination must be unique.'));
  }
}
function admin_menu_dropdown_settings_combos($type) {
  switch ($type) {
    case 'key':
      $options = array(
        '' => 'None',
        '65' => 'A',
        '66' => 'B',
        '67' => 'C',
        '68' => 'D',
        '69' => 'E',
        '70' => 'F',
        '71' => 'G',
        '72' => 'H',
        '73' => 'I',
        '74' => 'J',
        '75' => 'K',
        '76' => 'L',
        '77' => 'M',
        '78' => 'N',
        '79' => 'O',
        '80' => 'P',
        '81' => 'Q',
        '82' => 'R',
        '83' => 'S',
        '84' => 'T',
        '85' => 'U',
        '86' => 'V',
        '87' => 'W',
        '88' => 'X',
        '89' => 'Y',
        '90' => 'Z',
      );
      break;
    case 'modifier':
      $options = array(
        'ctrl + alt' => 'ctrl + alt',
        'ctrl + shift' => 'ctrl + shift',
        'ctrl + alt + shift' => 'ctrl + alt + shift',
      );
      break;
  }
  return $options;
}