In function restrict_ip_js_alter(), the whitelist keys from the hook are added to the default whitelist using the + operator:

$whitelisted_js_keys += Drupal::service('module_handler')->invokeAll('restrict_ip_whitelisted_js_keys');

However this doesn't work as expected because the + operator uses the key from the left side if the two arrays have the same keys. This causes the first three JS keys of your hook to always be ignored. Changing this line to use array_merge() solves the issue:

$whitelisted_js_keys = array_merge($whitelisted_js_keys, Drupal::service('module_handler')->invokeAll('restrict_ip_whitelisted_js_keys'));

Comments

jeroen_vreuls created an issue. See original summary.

sergiu stici’s picture

sergiu stici’s picture

Status: Active » Needs review
anybody’s picture

Version: 8.x-1.3 » 3.x-dev
Status: Needs review » Postponed (maintainer needs more info)

Cleaning up the module versions with Drupal 8 & 9 compatible 3.x release. We have to sort out outdated issues to focus on 3.x stabilization. Older Drupal 8 versions (8.x-2.x and 8.x-1.x) will be deprecated soon, so it doesn't make much sense anymore to fix them. Please instead retest if this issue is still relevant for latest 3.x version. If you should experience other issues, please create a separate issue for that, if not already existing.

If the issue from this request still exists in 3.x, please create a Merge Request (MR) against the latest 3.x-dev version to fix the issue and tell us about the actual problem and expected result.

Thank you very much! Let's get this module fixed together as community :)

siemen_hermans’s picture

Providing an updated patch for the 4.x-dev version

anybody’s picture

Version: 3.x-dev » 4.x-dev
Status: Postponed (maintainer needs more info) » Needs review
anybody’s picture

anybody’s picture

Status: Needs review » Needs work
Related issues: +#3347649: Use of hook_js_alter breaks core JS cache

Could this please be turned into a MR? @siemen_hermans?

anybody’s picture

  • smustgrave committed 89c26c43 on 5.0.x
    Issue #3018795 by sergiu stici, siemen_hermans, anybody: Hook...
smustgrave’s picture

Version: 4.x-dev » 5.0.x-dev
Status: Needs work » Fixed

Will include in 5.0.x branch.

Status: Fixed » Closed (fixed)

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