admin_menu_dropdown.module in Admin Menu Hider 6.2
Same filename and directory in other branches
Adds the ability to show/hide the Drupal Administration Menu via a selected behavior
File
admin_menu_dropdown.moduleView source
<?php
/**
* @file
* Adds the ability to show/hide the Drupal Administration Menu via a selected behavior
*/
/**
* Implementation of hook_menu().
*/
function admin_menu_dropdown_menu() {
$items = array();
$items['admin_menu_dropdown/js'] = array(
'title' => 'Admin Menu Dropdown JS',
'page callback' => 'admin_menu_dropdown_js',
'access arguments' => array(
'access administration menu',
),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implementation of hook_init().
*/
function admin_menu_dropdown_init() {
if (user_access('access administration menu')) {
$js = array();
$behaviors = admin_menu_dropdown_behaviors();
drupal_add_js(drupal_get_path('module', 'admin_menu_dropdown') . '/admin_menu_dropdown.js', 'module');
// Set visibility tweak behavior.
$js['behavior'] = variable_get('admin_menu_dropdown_behavior', 'amd_key_combo');
// Set default visibility tweak status.
$js['hidden'] = isset($_SESSION['admin_menu_visibility']) ? $js['hidden'] = $_SESSION['admin_menu_visibility'] : (variable_get('admin_menu_dropdown_hide', TRUE) ? "1" : "0");
// Add behavior specific CSS
if (isset($behaviors['data'][variable_get('admin_menu_dropdown_behavior', 'amd_key_combo')]['css'])) {
drupal_add_css($behaviors['data'][variable_get('admin_menu_dropdown_behavior', 'amd_key_combo')]['css'], 'module');
}
// Add behavior specific JavaScript
if (isset($behaviors['data'][variable_get('admin_menu_dropdown_behavior', 'amd_key_combo')]['js'])) {
drupal_add_js($behaviors['data'][variable_get('admin_menu_dropdown_behavior', 'amd_key_combo')]['js'], 'module');
}
// Add behavior specific JavaScript variables
if (isset($behaviors['data'][variable_get('admin_menu_dropdown_behavior', 'amd_key_combo')]['js_vars']) && function_exists($behaviors['data'][variable_get('admin_menu_dropdown_behavior', 'amd_key_combo')]['js_vars'])) {
$js = call_user_func($behaviors['data'][variable_get('admin_menu_dropdown_behavior', 'amd_key_combo')]['js_vars'], $js);
}
drupal_add_js(array(
'admin_menu' => array(
'visibility' => $js,
),
), 'setting');
}
}
/**
* 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');
$behaviors = admin_menu_dropdown_behaviors();
// Render Buttons below extra settings form
$form['buttons']['#weight'] = '1';
// Add Global Admin Menu Dropdown settings
$form['admin_menu_dropdown'] = array(
'#type' => 'fieldset',
'#title' => 'Administration Menu Dropdown',
);
$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 Administration menu is hidden by default'),
);
if (!isset($form['admin_menu_position_fixed'])) {
$form['admin_menu_dropdown']['admin_menu_dropdown_position'] = array(
'#type' => 'select',
'#title' => t('Admin Menu Dropdown position style'),
'#options' => array(
'static' => 'Static',
'fixed' => 'Fixed',
),
'#default_value' => variable_get('admin_menu_dropdown_position', 'fixed'),
'#description' => t('<strong>Static:</strong> Administration menu will appear at the top of the page requiring you to scroll up to see it.<br />
<strong>Fixed:</strong> Administration menu will appear at the top of the window no matter where you are on the page. <em>(May not work in all browsers)</em>'),
);
}
$form['admin_menu_dropdown']['admin_menu_dropdown_behavior'] = array(
'#type' => 'select',
'#title' => t('Admin Menu Dropdown behavior'),
'#options' => $behaviors['list'],
'#default_value' => variable_get('admin_menu_dropdown_behavior', 'amd_key_combo'),
);
// Add all behavior specific settings
foreach ($behaviors['data'] as $behavior => $data) {
if (isset($data['settings']) && function_exists($data['settings'])) {
$form['admin_menu_dropdown'][$behavior] = array(
'#type' => 'fieldset',
'#title' => $data['title'] . t(' settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['admin_menu_dropdown'][$behavior][] = call_user_func($data['settings']);
}
}
}
}
function admin_menu_dropdown_behaviors() {
foreach (module_invoke_all('amd_behavior') as $behavior => $data) {
$behaviors['list'][$behavior] = $data['title'];
$behaviors['data'][$behavior] = $data;
}
return $behaviors;
}
function admin_menu_dropdown_amd_behavior() {
include_once drupal_get_path('module', 'admin_menu_dropdown') . '/behaviors/key_combo/key_combo.inc';
return array(
'amd_icon_hotspot' => array(
'title' => 'Icon Hotspot',
'js' => drupal_get_path('module', 'admin_menu_dropdown') . '/behaviors/icon_hotspot/icon_hotspot.js',
),
'amd_key_combo' => array(
'title' => 'Key Combo',
'settings' => 'admin_menu_dropdown_key_combo_settings',
'js' => drupal_get_path('module', 'admin_menu_dropdown') . '/behaviors/key_combo/key_combo.js',
'js_vars' => 'admin_menu_dropdown_key_combo_js_vars',
),
);
}
function admin_menu_dropdown_js() {
$args = func_get_args();
switch ($args[0]) {
case 'visibility':
$_SESSION['admin_menu_visibility'] = $args[1] == 'hide' ? 1 : 0;
print drupal_json($_SESSION['admin_menu_visibility']);
break;
}
exit;
}
Functions
Name![]() |
Description |
---|---|
admin_menu_dropdown_amd_behavior | |
admin_menu_dropdown_behaviors | |
admin_menu_dropdown_form_alter | Implementation of hook_form_alter(). |
admin_menu_dropdown_init | Implementation of hook_init(). |
admin_menu_dropdown_js | |
admin_menu_dropdown_menu | Implementation of hook_menu(). |