stickynav.module in Sticky Navigation 8
Same filename and directory in other branches
Make a menu or some other element on the page stick on top when you scroll.
File
stickynav.moduleView source
<?php
/**
* @file
* Make a menu or some other element on the page stick on top when you scroll.
*/
/**
* Implements hook_page_attachments().
*/
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'),
),
];
}
}
Functions
Name | Description |
---|---|
stickynav_page_attachments | Implements hook_page_attachments(). |