tacjs.module in TacJS 8.4
Same filename and directory in other branches
The main file for the TacJS module.
Comply to the European cookie law using tarteaucitron.js.
File
tacjs.moduleView source
<?php
/**
* @file
* The main file for the TacJS module.
*
* Comply to the European cookie law using tarteaucitron.js.
*/
/**
* Implements hook_page_attachments().
*
* Insert JavaScript to the appropriate scope/region of the page.
*/
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'),
];
$page['#attached']['drupalSettings']['tacjs'] = $js_settings;
$page['#attached']['library'][] = 'tacjs/tacjs';
$page['#attached']['library'][] = 'tacjs/tarteaucitron.' . $lang . '.js';
}
}
/**
* Implements hook_library_info_build().
*
* Add tarteaucitron translations dynamically.
*/
function tacjs_library_info_build() {
$libraries = [];
/** @var \Drupal\Core\File\FileSystemInterface $fileSystem */
$fileSystem = Drupal::service('file_system');
foreach ($fileSystem
->scanDirectory(drupal_get_path('module', 'tacjs') . '/assets/vendor/tarteaucitron.js/lang/', '/tarteaucitron\\.(\\w+)\\.js/') as $file) {
$libraries[$file->filename] = [
'js' => [
'/' . $file->uri => [],
],
];
}
return $libraries;
}
Functions
Name![]() |
Description |
---|---|
tacjs_library_info_build | Implements hook_library_info_build(). |
tacjs_page_attachments | Implements hook_page_attachments(). |