-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_menu_by_role.module
63 lines (60 loc) · 2.23 KB
/
admin_menu_by_role.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
<?php
/**
* Implementation of hook_menu().
*/
function admin_menu_by_role_menu() {
$items = array();
$items['admin/settings/admin_menu/roles'] = array(
'title' => 'Role settings',
'description' => t('Manage which menu is used in the admin_menu'),
'page callback' => 'drupal_get_form',
'page arguments' => array('admin_menu_by_role_settings_form'),
'access callback' => 'user_access',
'access arguments' => array('access menumanager'),
'file' => 'admin_menu_by_role.settings.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);
$items['admin/settings/admin_menu/settings'] = array(
'title' => 'Settings',
'description' => 'Adjust administration menu settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array('admin_menu_theme_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'admin_menu.inc',
'path' => drupal_get_path('module', 'admin_menu'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
return $items;
}
/**
* Implementation of hook_theme().
*/
function admin_menu_by_role_theme() {
return array(
'admin_menu_by_role_settings_form' => array(
'arguments' => array('form' => NULL),
'file' => 'admin_menu_by_role.settings.inc',
),
);
}
/**
* Implementation of hook_admin_menu_output_alter().
*/
function admin_menu_by_role_admin_menu_output_alter(&$content) {
// Change the administration menu based on role type
global $user;
$menu_name = _admin_menu_by_role_get_role_selected_admin_menu($user);
$selected_menu = ($menu_name) ? $menu_name : 'admin_menu';
// Add administration menu.
$content['menu'] = admin_menu_links_menu(menu_tree_all_data($selected_menu)); //TODO: hier menu zetten op basis van rol
$content['menu']['#theme'] = 'admin_menu_links';
// Ensure the menu tree is rendered between the icon and user links.
$content['menu']['#weight'] = 0;
// Do not sort the menu tree, since it is sorted already.
$content['menu']['#sorted'] = TRUE;
}
function _admin_menu_by_role_get_role_selected_admin_menu($user) {
return db_result(db_query('SELECT name FROM {admin_menu_role} WHERE rid IN(' . implode(',', array_keys($user->roles)) . ') ORDER BY weight ASC LIMIT 1'));
}