You are here

popup_dialog.module in Popup Dialog 8

Same filename and directory in other branches
  1. 8.2 popup_dialog.module

Contains popup_dialog.module..

File

popup_dialog.module
View source
<?php

/**
 * @file
 * Contains popup_dialog.module..
 */
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function popup_dialog_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    // Main module help for the popup_dialog module.
    case 'help.page.popup_dialog':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Popup dialog box based on user browser session.') . '</p>';
      return $output;
    default:
  }
}

/**
 * Implements hook_page_attachments().
 */
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;
  }
}

Functions