-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_menu_path.module
79 lines (67 loc) · 2.61 KB
/
admin_menu_path.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* Implementation of hook_init().
*/
function admin_menu_path_init() {
if (!module_exists('admin_menu')) {
drupal_set_message('The Administration Menu Paths module requires the Administration Module.');
}
else {
if (FALSE === admin_menu_path_get_mode()) {
module_invoke('admin_menu', 'suppress');
}
}
}
/**
* Implementation of hook_form_alter().
*
* Add the path config area to the admin menu settings form.
*/
function admin_menu_path_form_alter(&$form, &$form_state, $form_id) {
if ('admin_menu_theme_settings' == $form_id) {
$form['tweaks']['admin_menu_path_mode'] = array(
'#title' => t('Path display control mode'),
'#description' => t('Select how you would like the paths below to control where the Administration Menu displays.'),
'#type' => 'radios',
'#default_value' => variable_get('admin_menu_path_mode', 0),
'#options' => array(t('Show on only the following pages:'), t('Show on all pages except the following:')),
);
$form['tweaks']['admin_menu_path_display'] = array(
'#title' => t('Exclude/Include on the following pages'),
'#description' => t('Each line should contain a Drupal path for pages where you would like the !module to be excluded/included (depending on which mode you\'ve selected). Omit beginning and end slashes. Use * for wildcard; !front_tag for homepage.', array('!module' => 'Administration menu', '!front_tag' => '<front>')),
'#type' => 'textarea',
'#rows' => 4,
'#resizable' => true,
'#default_value' => variable_get('admin_menu_path_display', ''),
);
}
}
/**
* Determine whether the current path allows or disallows menu display.
* Return TRUE to display, FALSE to hide.
*
* $mode 0 = Display everywhere but xyz.
* $mode 1 = Display only on xyz.
*/
function admin_menu_path_get_mode() {
$mode = variable_get('admin_menu_path_mode', 0);
$selected_pages = explode("\n", variable_get('admin_menu_path_display', ''));
if (empty($selected_pages)) {
return ($mode) ? TRUE : FALSE;
}
$path = request_uri();
$path = ($path == '/') ? '<front>' : trim($path, '/');
if (in_array($path, $selected_pages)) {
return ($mode) ? FALSE : TRUE;
}
foreach ($selected_pages as $page) {
$page = trim(trim($page), '/');
$pattern_wrapper = (substr(trim($page), -1) == '*') ? '/^(%s)/i' : '/^(%s)$/i';
$pattern = str_replace(array('/', '*'), array('\/', '((.)+)'), $page);
$pattern = sprintf($pattern_wrapper, $pattern);
if (preg_match($pattern, $path)) {
return ($mode) ? FALSE : TRUE;
}
}
return ($mode) ? TRUE : FALSE;
}