You are here

function simple_cookie_compliance_page_top in Simple Cookie Compliance 8

Implements hook_page_top().

File

./simple_cookie_compliance.module, line 35
Contains simple_cookie_compliance.module.

Code

function simple_cookie_compliance_page_top(array &$page_top) {
  $config = \Drupal::config('simple_cookie_compliance.settings');
  $use_no_script = $config
    ->get('no_script', TRUE);
  $message = $config
    ->get('message.value');
  $message_format = $config
    ->get('message.format');
  $agree_button = $config
    ->get('agree_button');
  if ($use_no_script) {
    $page_top['simple_cookie_compliance'] = [
      '#theme' => 'simple_cookie_compliance',
      '#use_no_script' => $use_no_script,
      '#message_text' => check_markup($message, $message_format),
    ];
  }
  $js_template = [
    '#theme' => 'simple_cookie_compliance',
    '#use_no_script' => FALSE,
    '#message_text' => check_markup($message, $message_format),
    '#agree_button' => $agree_button,
  ];
  $rendered = \Drupal::service('renderer')
    ->renderPlain($js_template);
  $expires = $config
    ->get('expires');
  $page_top['#attached']['drupalSettings']['simple_cookie_compliance']['template'] = $rendered;
  $page_top['#attached']['drupalSettings']['simple_cookie_compliance']['expires'] = $expires;
}