admin_menu_dropdown.module in Admin Menu Hider 5.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($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/admin_menu/amd_js',
'title' => 'Admin Menu Dropdown JS',
'callback' => 'admin_menu_dropdown_js',
'access' => user_access('access administration menu'),
'type' => MENU_CALLBACK,
);
}
return $items;
}
/**
* Implementation of hook_init().
*/
function admin_menu_dropdown_init() {
if (user_access('access administration menu')) {
$behaviors = admin_menu_dropdown_behaviors();
$js = '';
$js .= "amdBehavior = '" . variable_get('admin_menu_dropdown_behavior', 'amd_key_combo') . "'; ";
$js .= "amdPosition = '" . variable_get('admin_menu_dropdown_position', 'fixed') . "'; ";
if (isset($_SESSION['amd_status'])) {
$js .= "amdHidden = " . ($_SESSION['amd_status'] == 'off' ? "1" : "0") . "; ";
}
else {
$js .= "amdHidden = " . (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']);
}
drupal_add_js(drupal_get_path('module', 'admin_menu_dropdown') . '/admin_menu_dropdown.js', 'module');
drupal_add_js($js, 'inline');
}
}
/**
* Implementation of hook_form_alter().
*/
function admin_menu_dropdown_form_alter($form_id, &$form) {
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',
'css' => drupal_get_path('module', 'admin_menu_dropdown') . '/behaviors/icon_hotspot/icon_hotspot.css',
'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',
'css' => drupal_get_path('module', 'admin_menu_dropdown') . '/behaviors/key_combo/key_combo.css',
'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() {
$_SESSION['amd_status'] = arg(5);
print drupal_json($_SESSION['amd_status']);
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(). |