hook_js_alter

hook_js_alter(&$javascript, \Drupal\Core\Asset\AttachedAssetsInterface $assets)

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_js_defaults()

\Drupal\Core\Asset\AssetResolver

Related topics

Hooks
Define functions that alter the behavior of Drupal core.

File

core/lib/Drupal/Core/Render/theme.api.php, line 817
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_get_path('module', 'jquery_update') . '/jquery.js';
}
doc_Drupal
2016-10-29 09:18:17
Comments
Leave a Comment

Please login to continue.