You are here

function popup_dialog_page_attachments in Popup Dialog 8

Same name and namespace in other branches
  1. 8.2 popup_dialog.module \popup_dialog_page_attachments()

Implements hook_page_attachments().

File

./popup_dialog.module, line 29
Contains popup_dialog.module..

Code

function popup_dialog_page_attachments(array &$attachments) {
  $attachments['#attached']['library'][] = 'popup_dialog/dialog_box';
  $config = \Drupal::config('popup_dialog.settings');
  $enabled = $config
    ->get('popup_enabled');
  $attachments['#attached']['drupalSettings']['enabled'] = $enabled;

  // Get the cookie if available else pass the configs to JS.
  $mycookie = \Drupal::request()->cookies
    ->get('FirstUser');
  if ($mycookie != 1 && $enabled == 1) {
    $title = $config
      ->get('popup_box_title');
    $body_raw = $config
      ->get('popup_box_body');
    $body = $body_raw['value'];
    $delay = $config
      ->get('delay');
    $top = $config
      ->get('popup_top_position');
    $attachments['#attached']['drupalSettings']['title'] = $title;
    $attachments['#attached']['drupalSettings']['body'] = $body;
    $attachments['#attached']['drupalSettings']['delay'] = $delay;
    $attachments['#attached']['drupalSettings']['top'] = $top;
  }
}