annotate core/modules/shortcut/shortcut.api.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /**
Chris@0 4 * @file
Chris@0 5 * Hooks provided by the Shortcut module.
Chris@0 6 */
Chris@0 7
Chris@0 8 /**
Chris@0 9 * @addtogroup hooks
Chris@0 10 * @{
Chris@0 11 */
Chris@0 12
Chris@0 13 /**
Chris@0 14 * Return the name of a default shortcut set for the provided user account.
Chris@0 15 *
Chris@0 16 * This hook allows modules to define default shortcut sets for a particular
Chris@0 17 * user that differ from the site-wide default (for example, a module may want
Chris@0 18 * to define default shortcuts on a per-role basis).
Chris@0 19 *
Chris@0 20 * The default shortcut set is used only when the user does not have any other
Chris@0 21 * shortcut set explicitly assigned to them.
Chris@0 22 *
Chris@0 23 * Note that only one default shortcut set can exist per user, so when multiple
Chris@0 24 * modules implement this hook, the last (i.e., highest weighted) module which
Chris@0 25 * returns a valid shortcut set name will prevail.
Chris@0 26 *
Chris@0 27 * @param $account
Chris@0 28 * The user account whose default shortcut set is being requested.
Chris@0 29 * @return string
Chris@0 30 * The name of the shortcut set that this module recommends for that user, if
Chris@0 31 * there is one.
Chris@0 32 */
Chris@0 33 function hook_shortcut_default_set($account) {
Chris@0 34 // Use a special set of default shortcuts for administrators only.
Chris@0 35 $roles = \Drupal::entityManager()->getStorage('user_role')->loadByProperties(['is_admin' => TRUE]);
Chris@0 36 $user_admin_roles = array_intersect(array_keys($roles), $account->getRoles());
Chris@0 37 if ($user_admin_roles) {
Chris@0 38 return 'admin-shortcuts';
Chris@0 39 }
Chris@0 40 }
Chris@0 41
Chris@0 42 /**
Chris@0 43 * @} End of "addtogroup hooks".
Chris@0 44 */