tacjs.module in TacJS 8
Same filename and directory in other branches
The module file.
File
tacjs.moduleView source
<?php
/**
* @file
*
* The module file.
*/
/**
* Implements hook_page_attachments().
*/
function tacjs_page_attachments(&$page) {
/* Initial JS. */
$config = \Drupal::getContainer()
->get('config.factory')
->getEditable('tacjs.admin_settings_form');
$page['#attached']['library'][] = 'tacjs/tarteaucitron';
$services_tacjs = \Drupal::service('tacjs.settings')
->getFieldsSelects('module');
// @var $social_networks.
if (!empty($services_tacjs['social_networks'])) {
$social_networks = $services_tacjs['social_networks'];
foreach ($social_networks as $k => $item) {
$page['#attached']['library'][] = 'tacjs/tac' . $item['name'];
$page['#attached']['drupalSettings'][$item['value']]['value'] = !empty($config
->get($item['value'])) ? $config
->get($item['value']) : '';
}
}
// @var $apis.
if (!empty($services_tacjs['apis'])) {
$apis = $services_tacjs['apis'];
foreach ($apis as $k => $item) {
$page['#attached']['library'][] = 'tacjs/tac' . $item['name'];
$page['#attached']['drupalSettings'][$item['value']]['value'] = !empty($config
->get($item['value'])) ? $config
->get($item['value']) : '';
}
}
// @var $comment.
if (!empty($services_tacjs['comment'])) {
$comment = $services_tacjs['comment'];
foreach ($comment as $k => $item) {
$page['#attached']['library'][] = 'tacjs/tac' . $item['name'];
$page['#attached']['drupalSettings'][$item['value']]['value'] = !empty($config
->get($item['value'])) ? $config
->get($item['value']) : '';
}
}
// @var $mesure_audience .
if (!empty($services_tacjs['mesure_audience'])) {
$mesure_audience = $services_tacjs['mesure_audience'];
foreach ($mesure_audience as $k => $item) {
$page['#attached']['library'][] = 'tacjs/tac' . $item['name'];
$page['#attached']['drupalSettings'][$item['value']]['value'] = !empty($config
->get($item['value'])) ? $config
->get($item['value']) : '';
if (isset($item['value_'])) {
$page['#attached']['drupalSettings'][$item['value_']]['value'] = !empty($config
->get($item['value_'])) ? $config
->get($item['value_']) : '';
}
}
}
// @var $support .
if (!empty($services_tacjs['support'])) {
$support = $services_tacjs['support'];
foreach ($support as $k => $item) {
$page['#attached']['library'][] = 'tacjs/tac' . $item['name'];
$page['#attached']['drupalSettings'][$item['value']]['value'] = !empty($config
->get($item['value'])) ? $config
->get($item['value']) : '';
}
}
// @var $video .
$videos = $config
->get('type_video');
if (!empty($videos)) {
foreach ($videos as $k => $vid) {
$page['#attached']['library'][] = 'tacjs/tac' . $vid;
}
}
// @var $regie_pub .
$regie_pub = $services_tacjs['regie_pub'];
if (!empty($regie_pub)) {
foreach ($regie_pub['options'] as $k => $value) {
$page['#attached']['library'][] = 'tacjs/tac' . $value;
}
unset($regie_pub['options']);
if (!empty($regie_pub)) {
foreach ($regie_pub as $k => $item) {
$page['#attached']['library'][] = 'tacjs/tac' . $item['name'];
$page['#attached']['drupalSettings'][$item['value']]['value'] = !empty($config
->get($item['value'])) ? $config
->get($item['value']) : '';
}
}
}
/*$test = \Drupal::service('library.discovery')->getLibraryByName('tacjs', 'tacjs/tacgoogleanalytics');
$name = 'tacjs/tacgoogleanalytics'; // your library name here.
if (function_exists('libraries_get_path') && file_exists(libraries_get_path($name))) {
}*/
}
Functions
Name | Description |
---|---|
tacjs_page_attachments | Implements hook_page_attachments(). |