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
Comment #2
svenryen commentedYes, seems that this shouldn't run on excluded pages. Thanks for the report. We'll try to have a fix for this shortly.
Comment #3
svenryen commentedComment #4
azwart commentedI 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.
Comment #5
svenryen commentedPatch 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.
Comment #7
svenryen commentedComment #8
svenryen commentedCode 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.
Comment #9
svenryen commentedActually, 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.
Comment #10
azwart commentedI 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.
Comment #11
svenryen commentedI don't really expect any showstoppers in D9.
We should test it in D7 though.
Comment #12
svenryen commentedComment #13
neslee canil pinto@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
Comment #14
svenryen commentedMade an attempt at reroll from the diff, needs a test :)
Comment #15
svenryen commentedTake 2 at re-roll.
Comment #16
neslee canil pinto#15 works fine, thanks.
Comment #19
neslee canil pinto