I am trying to specify another custom ajax.js file in place of js/misc/ajax.js using hook_js_alter(&$variables) but this fails. Upon inspection of the &$variables array, my target file js/misc/ajax.js does not appear there at all and thus it is not possible to override it using HOOK_js_alter(&$variables)

CommentFileSizeAuthor
#3 2016-07-13 20_30_31-Products.png84.38 KBW.M.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

W.M. created an issue. See original summary.

markhalliwell’s picture

Status: Active » Closed (works as designed)
Related issues: +#2764569: How to override js/misc/ajax.js within a Bootstrap's subtheme
  1. Do not create a new issue when you created the exact same issue that was already marked as "Closed (works as designed)".
  2. The function signature for hook_js_alter is hook_js_alter(&$javascript), not $variables... granted it doesn't really matter what you decide to name your arguments, but still... it makes it confusing to go against existing DOCs.
  3. Your target file will not always appear because the file is not always loaded on every page. This is by design. You must check if it exists first before overriding it.
  4. If the base theme replaces the entire file, which in this case it does, the key index will be the file path to the file in the base theme, not where it was originally found. See bootstrap_js_alter().
  5. I know for a fact that this works because I have overridden ajax.js in sub-themes many of times, for various reasons.
W.M.’s picture

As you can see in the attached image, Bootstrap base theme's js/misc/ajax.js cannot be found inside the $javascript array of hook_js_alter(&$javascript), however it is loaded on the page as can be seen inside HTML source.