You are here

function livechat_page_attachments in LiveChat 8

Same name and namespace in other branches
  1. 8.2 livechat.module \livechat_page_attachments()

Implements hook_page_attachments().

File

./livechat.module, line 40
LiveChat module.

Code

function livechat_page_attachments(array &$attachments) {
  $configs = livechat_configs();
  if (!empty($configs
    ->get('livechat_enabled'))) {

    // Validate permissions for current user and visibility for current path.
    $user = \Drupal::currentUser();
    if ($user
      ->hasPermission('use livechat') && livechat_check_visibility()) {
      $license = $configs
        ->get('livechat_license');
      $group_id = $configs
        ->get('livechat_group');
      $settings = livechat_attach_js_settings($license, $group_id);
      if (!empty($settings)) {
        $attachments['#attached']['drupalSettings']['LiveChat'] = $settings;
        $attachments['#attached']['library'][] = 'livechat/livechat';
      }
    }
  }
}