8 theme.api.php hook_js_alter(&$javascript, \Drupal\Core\Asset\AttachedAssetsInterface $assets)
7 system.api.php hook_js_alter(&$javascript)

Perform necessary alterations to the JavaScript before it is presented on the page.


$javascript: An array of all JavaScript being presented on the page.

\Drupal\Core\Asset\AttachedAssetsInterface $assets: The assets attached to the current response.

See also



Related topics

2 functions implement hook_js_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

locale_js_alter in core/modules/locale/locale.module
Implements hook_js_alter().
simpletest_js_alter in core/modules/simpletest/simpletest.module
Implements hook_js_alter().
1 invocation of hook_js_alter()
AssetResolver::getJsAssets in core/lib/Drupal/Core/Asset/AssetResolver.php
Returns the JavaScript assets for the current response's libraries.


core/lib/Drupal/Core/Render/theme.api.php, line 814
Hooks and documentation related to the theme and render system.


function hook_js_alter(&$javascript, \Drupal\Core\Asset\AttachedAssetsInterface $assets) {
  // Swap out jQuery to use an updated version of the library.
  $javascript['core/assets/vendor/jquery/jquery.min.js']['data'] = drupal_get_path('module', 'jquery_update') . '/jquery.js';