You are here

function hook_js_alter in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Render/theme.api.php \hook_js_alter()
  2. 7 modules/system/system.api.php \hook_js_alter()
  3. 9 core/lib/Drupal/Core/Render/theme.api.php \hook_js_alter()

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

Parameters

$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

\Drupal\Core\Asset\AssetResolver

Related topics

3 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.

ckeditor5_js_alter in core/modules/ckeditor5/ckeditor5.module
Implements hook_js_alter().
common_test_js_alter in core/modules/system/tests/modules/common_test/common_test.module
Implements hook_js_alter().
locale_js_alter in core/modules/locale/locale.module
Implements hook_js_alter().
1 invocation of hook_js_alter()
AssetResolver::getJsAssets in core/lib/Drupal/Core/Asset/AssetResolver.php

File

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

Code

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::service('extension.list.module')
    ->getPath('jquery_update') . '/jquery.js';
}