diff --git a/tmgmt.module b/tmgmt.module index 7ff9478..e80ade3 100644 --- a/tmgmt.module +++ b/tmgmt.module @@ -1074,16 +1074,12 @@ function tmgmt_cart_source_overview_validate(array $form, FormStateInterface $fo * @} End of "addtogroup tmgmt_cart". */ -function tmgmt_toolbar() { - $items = []; - $items['tmgmt'] = [ - '#type' => 'toolbar_item', - '#attached' => [ - 'library' => [ - 'tmgmt/drupal.tmgmt.toolbar', - ], - ], - ]; - - return $items; +/** + * Implements hook_page_attachments(). + */ +function tmgmt_page_attachments(array &$attachments) { + // Load the CSS only if the user has the permission to access the toolbar. + if (\Drupal::currentUser()->hasPermission('access toolbar')) { + $attachments['#attached']['library'][] = 'tmgmt/drupal.tmgmt.toolbar'; + } }