function cookie_banner_page_attachments in Cookie_Banner 8
Implements hook_page_attachments().
File
- ./
cookie_banner.module, line 11 - Main module file.
Code
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';
}
}