livechat.module in LiveChat 8.3
Same filename and directory in other branches
LiveChat module.
File
livechat.moduleView 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
Name![]() |
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. |