cookies-1.0.3/modules/cookies_ivw/cookies_ivw.module
modules/cookies_ivw/cookies_ivw.module
<?php
/**
* @file
* Contains cookies_ivw.module.
*/
use Drupal\cookies\Constants\CookiesConstants;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Template\Attribute;
/**
* Implements hook_help().
*/
function cookies_ivw_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the cookies_ivw module.
case 'help.page.cookies_ivw':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Submodule of cookies to manage IVW Integration implemented by so named module.') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_page_attachments().
*/
function cookies_ivw_page_attachments(&$page) {
$doKo = Drupal::service('cookies.knock_out')->doKnockOut();
if ($doKo && isset($page["#attached"]["html_head"])) {
foreach ($page["#attached"]["html_head"] as $key => $head_tag) {
$scripts = ['ivw_library'];
foreach ($scripts as $script) {
if (in_array($script, $head_tag)) {
$attr = (isset($head_tag[0]['#attributes'])) ? $head_tag[0]['#attributes'] : [];
$attr = array_merge(
$attr,
[
'type' => CookiesConstants::COOKIES_SCRIPT_KO_TYPE,
'id' => "cookies_{$script}",
'data-cookieconsent' => 'ivw',
],
);
$page["#attached"]["html_head"][$key][0]['#attributes'] = new Attribute($attr);
$page["#attached"]["library"][] = 'cookies_ivw/ivw';
break;
}
}
}
}
}
