You are here

function eu_cookie_compliance_js_alter in EU Cookie Compliance (GDPR Compliance) 7

Same name and namespace in other branches
  1. 8 eu_cookie_compliance.module \eu_cookie_compliance_js_alter()
  2. 7.2 eu_cookie_compliance.module \eu_cookie_compliance_js_alter()

Implements hook_js_alter().

File

./eu_cookie_compliance.module, line 753
EU cookie compliance primary module file.

Code

function eu_cookie_compliance_js_alter(&$javascript) {

  // Determine which array key holds the EUCC disabled script loader.
  $js_disabled_script_position = _eu_cookie_compliance_get_script_key($javascript);
  $popup_settings = eu_cookie_compliance_get_settings();
  if (!empty($popup_settings['disabled_javascripts'])) {
    $disabled_javascripts = $popup_settings['disabled_javascripts'];
    $disabled_javascripts = _eu_cookie_compliance_explode_multiple_lines($disabled_javascripts, FALSE);
    foreach ($disabled_javascripts as $script) {

      // Remove 'category:' if present.
      $parts = explode(':', $script);

      // Deal with absolute links with category.
      if (!empty($parts[2]) && strpos($parts[2], '//') === 0) {
        array_shift($parts);
        $script = implode(':', $parts);
      }
      else {
        if (!empty($parts[1]) && strpos($parts[1], '//') !== 0) {
          $script = end($parts);
        }
      }

      // Parse the string and drop the parameter that is a behavior name.
      if (strpos($script, '|') !== FALSE) {
        @(list($script, $attach_name) = explode('|', $script));
      }

      // https://www.drupal.org/project/eu_cookie_compliance/issues/3205742
      // Only add the script if it's actually present in the page scripts.
      if (array_key_exists($script, $javascript)) {
        unset($javascript[$script]);
      }
      else {
        _eu_cookie_compliance_remove_script_from_loader($javascript, $script, $js_disabled_script_position);
      }
    }
  }
}