shortcutperrole.module in Shortcut per Role 8
Allows users to manage customizable lists of shortcut links.
File
shortcutperrole.moduleView source
<?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();
}
Functions
Name | Description |
---|---|
shortcutperrole_help | Implements hook_help(). |
shortcutperrole_shortcut_default_set | Implements hook_shortcut_default_set() |
shortcutperrole_user_role_delete | Implements hook_ENTITY_TYPE_delete() for user_role entities. |
Constants
Name | Description |
---|---|
SHORTCUT_PER_ROLE_DEFAULT_SET | Default shortcut set for users. |