bu.module in Browser update 8
Same filename and directory in other branches
Drupal Module: Browser Update.
Adds a message to update for users on older web browsers.
File
bu.moduleView source
<?php
/**
* @file
* Drupal Module: Browser Update.
*
* Adds a message to update for users on older web browsers.
*/
/**
* Implements hook_page_attachments().
*/
function bu_page_attachments(array &$attachments) {
// Load the configuration settings.
$configurationSettings = \Drupal::config('bu.settings');
// Add the javascript location.
$drupalSettings = $configurationSettings
->get();
// Set the default scripts if needed.
if (empty($drupalSettings['source'])) {
$drupalSettings['source'] = '//browser-update.org/update.min.js';
}
// Determine which pages this block appears on.
$visibility_pages = $configurationSettings
->get('visibility_pages');
// Verify visibility if it is set.
if (!$configurationSettings
->get('test_mode') && !empty($visibility_pages)) {
// Check to make sure the current page matches the allowed paths.
$current_path = \Drupal::service('path.current')
->getPath();
$match = \Drupal::service('path.matcher')
->matchPath($current_path, $visibility_pages);
// If this page should not be showing the popup, exit.
if ($configurationSettings
->get('visibility_type') == 'hide' && $match || $configurationSettings
->get('visibility_type') == 'show' && !$match) {
return;
}
}
// Attach the library.
$attachments['#attached']['library'][] = 'bu/bu.checker';
$attachments['#attached']['drupalSettings']['bu'] = $drupalSettings;
}
Functions
Name | Description |
---|---|
bu_page_attachments | Implements hook_page_attachments(). |