shortcut.api.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. * @return string
  27. * The name of the shortcut set that this module recommends for that user, if
  28. * there is one.
  29. */
  30. function hook_shortcut_default_set($account) {
  31. // Use a special set of default shortcuts for administrators only.
  32. $roles = \Drupal::entityManager()->getStorage('user_role')->loadByProperties(['is_admin' => TRUE]);
  33. $user_admin_roles = array_intersect(array_keys($roles), $account->getRoles());
  34. if ($user_admin_roles) {
  35. return 'admin-shortcuts';
  36. }
  37. }
  38. /**
  39. * @} End of "addtogroup hooks".
  40. */