You are here

function seeds_toolbar_page_attachments in Seeds Toolbar 8

Implements hook_page_attachments().

File

./seeds_toolbar.module, line 79
Contains seeds_toolbar.module.

Code

function seeds_toolbar_page_attachments(array &$attachments) {

  // Get the current user.
  $user = \Drupal::currentUser();

  // Check for permission.
  if ($user
    ->hasPermission('access toolbar')) {
    $config = \Drupal::config('seeds_toolbar.settings');

    // Cache tags.
    $attachments['#cache']['tags'][] = $config
      ->getCacheTags()[0];

    // JS Libraries.
    $attachments['#attached']['library'][] = 'seeds_toolbar/toolbar.seeds';
    $attachments['#attached']['drupalSettings']['seeds_toolbar'] = [
      'compact' => $config
        ->get('compact'),
      'support' => $config
        ->get('support'),
      'style' => $config
        ->get('style'),
    ];
  }
}