Problem/Motivation

It seems that the `eu_cookie_compliance_js_alter` alter hook removes JS from the `disabled_javascripts` config unconditionally so it seems? We currently had issues for the admin pages where all the Maps were unable to render, even when we used the "Exclude admin pages" option. Debugging this further in the module, I've found the eu_cookie_compliance_js_alter hook. Correct me if I'm wrong, but I think this function should unset javascript only when permissions have been given OR when exclude conditions apply (excluded user roles, path matches, exclude admin pages etc...).

Disclaimer; I'm hesitant to call this issue, since I expect that this piece of code has been reviewed on disabling JS correctly, so I'm probably wrong in claiming this issue.

/**
 * Implements hook_js_alter().
 */
function eu_cookie_compliance_js_alter(&$javascript, AttachedAssetsInterface $assets) {
  $config = \Drupal::config('eu_cookie_compliance.settings');
  $disabled_javascripts = $config->get('disabled_javascripts');
  $disabled_javascripts = _eu_cookie_compliance_explode_multiple_lines($disabled_javascripts);

  foreach ($disabled_javascripts as $script) {
    // Remove 'category:' if present.
    $parts = explode('%3A', $script);
    if (count($parts) > 2) {
      array_shift($parts);
      $script = implode(':', $parts);
    }
    else {
      $script = end($parts);
    }
    // Parse the string and drop the parameter that is a behavior name.
    if (strpos($script, '%7C') !== FALSE) {
      @list($script, $attach_name) = explode('%7C', $script);
    }
    _eu_cookie_compliance_convert_relative_uri($script);

    unset($javascript[$script]);
  }
}

Steps to reproduce

We've provided the following geolocation scripts to the Disabled javascripts config. Note that when you add a Geolocation field with Google Maps form view that the field will not render its map.

modules/contrib/geolocation/js/geolocation-google-maps-api.js
modules/contrib/geolocation/js/geolocation-common-map.js|geolocationCommonMap

When removing the lines, the map will render again?

Proposed resolution

Make the unsetting of the disabled_javascripts conditional?

Remaining tasks

Tba

User interface changes

N/a

API changes

N/a

Data model changes

N/a

Comments

Ambidex created an issue. See original summary.

svenryen’s picture

Yes, seems that this shouldn't run on excluded pages. Thanks for the report. We'll try to have a fix for this shortly.

svenryen’s picture

Issue tags: +Novice
azwart’s picture

StatusFileSize
new1.39 KB

I encountered this problem as well and made a patch (my first patch, so go easy on me ;-)).
This seems to fix the issue, but hopefully someone else can check my code & verify.

svenryen’s picture

Status: Active » Needs review

Patch looks good. I'll test later and see if I can merge.

Here's a tip for your next contribution; when you upload the patch, you should also set Status to Needs Review so that the maintainers see that there's a patch waiting in the issue.

Status: Needs review » Needs work

The last submitted patch, 4: eu_cookie_compliance-3181478-4.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

svenryen’s picture

Status: Needs work » Needs review
svenryen’s picture

StatusFileSize
new1.96 KB

Code looks good, just one minor comment.

When you wrap code in a new if branch, it's common practice to indent the code it encompasses. Most IDEs will add colored markup to display you're not following good code practice, and there's also the option of running the PHPCodeSniffer tool with the Drupal code standard on your module code before you submit the patch.

I'm going to do a D7 patch and then I'll commit your code. Updated patch for 8.x is attached.

svenryen’s picture

Actually, while working on the 7.x patch I realized that there are other situations where the banner will not show. We can also exclude all admin pages as well as hide the banner for all users that are administrators.

Here's an updated patch for 8.x as well as a 7.x patch.

Would you be able to review these patches, @azwart (so you can tick off one more achievement)? You can reach out to me on Slack if you need any assistance while applying patches or testing the site.

azwart’s picture

I tested the 8.x patch on my existing Drupal 8.x install (which had the bug) -- that worked like it should. Sadly, at this time I'm not able to test the patch on a clean Drupal 9 install or a Drupal 7 install.

svenryen’s picture

I don't really expect any showstoppers in D9.
We should test it in D7 though.

svenryen’s picture

Assigned: Unassigned » neslee canil pinto
neslee canil pinto’s picture

Version: 8.x-1.13 » 8.x-1.x-dev
Status: Needs review » Reviewed & tested by the community

@svenryen tested your patch for drupal 8 and the issue which existed has been fixed. Moving it to RTBC.

Patch needs a reroll for drupal 7

svenryen’s picture

Made an attempt at reroll from the diff, needs a test :)

svenryen’s picture

Take 2 at re-roll.

neslee canil pinto’s picture

#15 works fine, thanks.

neslee canil pinto’s picture

Assigned: neslee canil pinto » Unassigned
Status: Reviewed & tested by the community » Fixed

  • svenryen committed baf741b on 7.x-2.x
    Merge branch '7.x-1.x' into 7.x-2.x
    
    * 7.x-1.x:
      Issue #3236586 by...
  • Neslee Canil Pinto committed d38c357 on 7.x-2.x authored by svenryen
    Issue #3181478 by svenryen, azwart, Neslee Canil Pinto: Javascripts are...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.