shortcut.api.php 1.3 KB

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