You are here

function stickynav_page_attachments in Sticky Navigation 8

Implements hook_page_attachments().

File

./stickynav.module, line 10
Make a menu or some other element on the page stick on top when you scroll.

Code

function stickynav_page_attachments(array &$attachments) {
  $theme = \Drupal::theme()
    ->getActiveTheme();
  $theme_name = $theme
    ->getName();
  $user = Drupal::currentUser();
  $config = Drupal::config('stickynav.settings.' . $theme_name);
  $enabled = $config
    ->get('enabled');
  $selector = $config
    ->get('selector');
  $excluded_roles = $config
    ->get('roles');
  if ($enabled && trim($selector) && !array_intersect($excluded_roles, $user
    ->getRoles())) {
    $attachments['#attached']['library'][] = 'stickynav/stickynav';
    $attachments['#attached']['drupalSettings']['stickynav'] = [
      'selector' => $selector,
      'offsets' => array(
        'selector' => $config
          ->get('offset'),
        'custom_offset' => $config
          ->get('custom_offset'),
      ),
    ];
  }
}