-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshortcutperrole.module
54 lines (47 loc) · 1.44 KB
/
shortcutperrole.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
<?php
/**
* @file
* Allows users to manage customizable lists of shortcut links.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Default shortcut set for users.
*/
define('SHORTCUT_PER_ROLE_DEFAULT_SET', 'default');
/**
* Implements hook_help().
*/
function shortcutperrole_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the shortcutperrole module.
case 'help.page.shortcutperrole':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Allows creating default shortcut per role') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_shortcut_default_set()
*/
function shortcutperrole_shortcut_default_set($account) {
//determine the highest rid of user & assign the shortcut set.
$all_roles = user_roles();
$user_roles = array_flip($account->getRoles());
$sorted_roles = array_intersect_key($all_roles, $user_roles);
if ($sorted_roles) {
$role = end($sorted_roles);
$config = \Drupal::config('shortcutperrole.settings');
$set = $config->get('role.' . $role->id());
}
$ss = isset($set) ? $set : SHORTCUT_PER_ROLE_DEFAULT_SET;
return $ss;
}
/**
* Implements hook_ENTITY_TYPE_delete() for user_role entities.
*/
function shortcutperrole_user_role_delete($role) {
$config = 'shortcutperrole.settings.role.' . $role->id();
\Drupal::service('config.factory')->getEditable($config)->delete();
}