You are here

function tacjs_page_attachments in TacJS 8.5

Same name and namespace in other branches
  1. 8.6 tacjs.module \tacjs_page_attachments()
  2. 8 tacjs.module \tacjs_page_attachments()
  3. 8.2 tacjs.module \tacjs_page_attachments()
  4. 8.3 tacjs.module \tacjs_page_attachments()
  5. 8.4 tacjs.module \tacjs_page_attachments()

Implements hook_page_attachments().

Insert JavaScript to the appropriate scope/region of the page.

File

./tacjs.module, line 15
The main file for the TacJS module.

Code

function tacjs_page_attachments(&$page) {
  if (!\Drupal::service('router.admin_context')
    ->isAdminRoute()) {
    $config = Drupal::config('tacjs.settings');
    $lang = Drupal::languageManager()
      ->getCurrentLanguage()
      ->getId();
    $js_settings = [
      'dialog' => $config
        ->get('dialog'),
      'services' => $config
        ->get('services'),
      'user' => $config
        ->get('user'),
      'texts' => $config
        ->get('texts'),
      'expire' => $config
        ->get('expire'),
    ];
    $page['#attached']['drupalSettings']['tacjs'] = $js_settings;
    $page['#attached']['library'][] = 'tacjs/tacjs';
    $page['#attached']['library'][] = 'tacjs/tarteaucitron.' . $lang . '.js';
  }
}