Repository URL to install this package:
|
Version:
2.0.2 ▾
|
novicell/dds_browser_info
/
dds_browser_info.module
|
|---|
<?php
use Drupal\Core\Template\Attribute;
/**
* Implements hook_theme().
*/
function dds_browser_info_theme() {
return [
'browser_info' => [
'variables' => [
'title' => NULL,
'body' => NULL,
'open' => NULL,
'close' => NULL,
'section_attributes' => [],
],
],
];
}
/**
* Implements hook_page_attachments().
*/
function dds_browser_info_page_attachments(array &$attachments) {
// Attach browser info styling to the head, so it won't be shown before styles
// are properly loaded.
$attachments['#attached']['library'][] = 'dds_browser_info/browser_info_styling';
}
/**
* Implements hook_page_bottom().
*/
function dds_browser_info_page_bottom(array &$page_bottom) {
// Get current theme.
$theme = \Drupal::theme()->getActiveTheme()->getName();
// Get system theme settings.
$config = \Drupal::config('system.theme');
if ($theme != $config->get('admin')) {
/** @var \Drupal\site_settings\SiteSettingsLoader $site_settings_loader */
$site_settings_loader = \Drupal::service('site_settings.loader');
$site_settings = $site_settings_loader->loadByFieldset('accessibility');
$section_attributes = new Attribute();
if (isset($site_settings['browser_info']) && !empty($browser_info = $site_settings['browser_info'])) {
$page_bottom['browser_info'] = [
'#theme' => 'browser_info',
'#title' => $browser_info['field_browser_info_header'],
'#body' => $browser_info['field_browser_info_body'],
'#section_attributes' => $section_attributes,
'#attached' => [
'library' => 'dds_browser_info/browser_info_no_js',
'drupalSettings' => [
'browserinfo' => [
'browserinfo_behavior' => 'display_until_accepted',
],
],
],
'#cache' => [
'tags' => ['site_settings_bundle:browser_info'],
],
];
// Adds more template data if javascript is enabled.
if (isset($browser_info['field_allow_javascript']) && $browser_info['field_allow_javascript'] == 1) {
$page_bottom['browser_info']['#open'] = $browser_info['field_browser_info_open'];
$page_bottom['browser_info']['#close'] = $browser_info['field_browser_info_close'];
$page_bottom['browser_info']['#attached'] = [
'library' => 'dds_browser_info/browser_info_js',
'drupalSettings' => [
'browserinfo' => [
'browserinfo_behavior' => isset($browser_info['field_browser_info_show_once']) && $browser_info['field_browser_info_show_once'] == 1 ? 'display_once' : 'display_until_accepted',
],
],
];
}
}
}
}