You are here

livechat.module in LiveChat 8.3

Same filename and directory in other branches
  1. 8 livechat.module
  2. 8.2 livechat.module
  3. 7 livechat.module

LiveChat module.

File

livechat.module
View source
<?php

/**
 * @file
 * LiveChat module.
 */

/**
 * Implements hook_page_attachments_alter().
 *
 * Adds livechat code when conditions are met.
 */
function livechat_page_attachments_alter(array &$page) {
  $config = \Drupal::config('livechat.settings');
  $path = \Drupal::service('path.current')
    ->getPath();
  if (empty($config
    ->get('licence_number'))) {
    return;
  }
  $is_admin_page = TRUE;
  if (!_livechat_active($path)) {
    $is_admin_page = FALSE;
  }
  $js_settings = [
    'licence_number' => $config
      ->get('licence_number'),
    'livechat_mobile' => $config
      ->get('livechat_mobile'),
    'is_admin_page' => $is_admin_page,
  ];
  $page['#attached']['drupalSettings']['livechat'] = $js_settings;
  $page['#attached']['library'][] = 'livechat/livechat';
}

/**
 * Helper function to check whether LiveChat is active.
 */
function _livechat_active($path) {
  $page_match = FALSE;
  if (strpos($path, "admin")) {
    $page_match = TRUE;
  }
  return $page_match;
}

/**
 * Implements hook_theme().
 */
function livechat_theme($existing, $type, $theme, $path) {
  return [
    'livechat_settings' => [
      'variables' => [],
    ],
  ];
}

Functions

Namesort descending Description
livechat_page_attachments_alter Implements hook_page_attachments_alter().
livechat_theme Implements hook_theme().
_livechat_active Helper function to check whether LiveChat is active.