function restrict_ip_js_alter in Restrict IP 8
Same name and namespace in other branches
- 8.2 restrict_ip.module \restrict_ip_js_alter()
- 7.2 restrict_ip.module \restrict_ip_js_alter()
- 7 restrict_ip.module \restrict_ip_js_alter()
- 3.x restrict_ip.module \restrict_ip_js_alter()
Implementation of hook_js_alter()
This function removes all javascript from the page with the exception of jQuery and any javascript provided by this module.
File
- ./
restrict_ip.module, line 106
Code
function restrict_ip_js_alter(&$javascript, AttachedAssetsInterface $assets) {
if (\Drupal::service('restrict_ip.service')
->userIsBlocked()) {
$whitelisted_js_keys = [
'core/assets/vendor/jquery/jquery.min.js',
'core/assets/vendor/jquery/jquery.js',
drupal_get_path('module', 'restrict_ip') . '/js/mail_fix.js',
];
$whitelisted_js_keys += Drupal::service('module_handler')
->invokeAll('restrict_ip_whitelisted_js_keys');
foreach (array_keys($javascript) as $key) {
if (!in_array($key, $whitelisted_js_keys)) {
unset($javascript[$key]);
}
}
}
}