function cookies_ivw_page_attachments in COOKiES Consent Management 1.0.x
Implements hook_page_attachments().
File
- modules/
cookies_ivw/ cookies_ivw.module, line 31 - Contains cookies_ivw.module.
Code
function cookies_ivw_page_attachments(&$page) {
$doKo = CookiesKnockOutService::getInstance()
->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' => 'application/json',
'id' => "cookies_{$script}",
]);
$page["#attached"]["html_head"][$key][0]['#attributes'] = new Attribute($attr);
$page["#attached"]["library"][] = 'cookies_ivw/ivw';
break;
}
}
}
}
}