You are here

cookies_ivw.module in COOKiES Consent Management 1.0.x

Contains cookies_ivw.module.

File

modules/cookies_ivw/cookies_ivw.module
View source
<?php

/**
 * @file
 * Contains cookies_ivw.module.
 */
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Template\Attribute;
use Drupal\cookies\CookiesKnockOutService;

/**
 * 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 = 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;
        }
      }
    }
  }
}

Functions