adminimal_admin_toolbar.module 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * @file
  4. * Functions to support adminimal admin toolbar.
  5. */
  6. /**
  7. * Implements hook_preprocess_HOOK().
  8. */
  9. function adminimal_admin_toolbar_preprocess_html(&$variables) {
  10. // Add adminimal-admin-toolbar class to the body.
  11. if (_adminimal_admin_toolbar_is_access()) {
  12. $variables['attributes']['class'][] = 'adminimal-admin-toolbar';
  13. }
  14. }
  15. /**
  16. * Implements hook_page_attachments_alter().
  17. */
  18. function adminimal_admin_toolbar_page_attachments_alter(array &$page) {
  19. // Attaches css assets globally.
  20. if (_adminimal_admin_toolbar_is_access()) {
  21. $page['#attached']['library'][] = 'adminimal_admin_toolbar/adminimal-admin-toolbar';
  22. }
  23. }
  24. /**
  25. * Implements hook_toolbar_alter().
  26. */
  27. function adminimal_admin_toolbar_toolbar_alter(&$items) {
  28. // Add class to the user tab so it can be moved to the right.
  29. if (_adminimal_admin_toolbar_is_access()) {
  30. $items['user']['#wrapper_attributes']['class'] = array('user-toolbar-tab');
  31. }
  32. }
  33. /**
  34. * Helper function for checking user permission.
  35. * We reallly only want to add styling and changes to toolbar when the user has
  36. * access.
  37. *
  38. * Returns TRUE or FALSE.
  39. */
  40. function _adminimal_admin_toolbar_is_access() {
  41. $user = \Drupal::currentUser();
  42. return $user->hasPermission('access toolbar');
  43. }