cookie_banner.module in Cookie_Banner 8
Same filename and directory in other branches
Main module file.
File
cookie_banner.moduleView source
<?php
/**
* @file
* Main module file.
*/
/**
* Implements hook_page_attachments().
*/
function cookie_banner_page_attachments(&$attachments) {
$config = \Drupal::config('cookie_banner.settings');
$anonymousUser = \Drupal::currentUser()
->isAnonymous();
if ($anonymousUser) {
$cookie_banner = array(
'#theme' => 'cookie_banner_message',
'#use_cookie_message' => $config
->get('use_cookie_message'),
'#more_info_message' => $config
->get('more_info_message'),
'#more_info_url' => $config
->get('more_info_url'),
);
$data['variables'] = array(
'cookie_banner_message' => \Drupal::service('renderer')
->renderRoot($cookie_banner)
->__toString(),
'cookie_banner_name' => preg_replace("[\\W]", "-", $_SERVER['HTTP_HOST'] . "-eu-cookie"),
'cookie_banner_duration' => time() + 60 * 60 * 24 * 90,
);
$attachments['#attached']['drupalSettings']['cookie_banner'] = $data['variables'];
$attachments['#attached']['library'][] = 'cookie_banner/cookie_banner';
}
}
/**
* Implements hook_theme().
*/
function cookie_banner_theme($existing, $type, $theme, $path) {
return array(
'cookie_banner_message' => array(
'template' => 'cookie-banner-message',
'variables' => array(
'use_cookie_message' => NULL,
'more_info_message' => NULL,
'more_info_url' => NULL,
),
'path' => $path . '/templates',
),
);
}
Functions
Name | Description |
---|---|
cookie_banner_page_attachments | Implements hook_page_attachments(). |
cookie_banner_theme | Implements hook_theme(). |