1

For some reason a bunch of core JS files are not being loaded. I've had to manually add them in with a module hook_js_alter function like so:

function MYMODULE_js_alter(&$js) {
    drupal_add_js('misc/jquery.js', array('group' => JS_LIBRARY, 'weight' => -100, 'every_page' => TRUE, 'scope' => 'header'));
    drupal_add_js('misc/jquery.once.js', array('group' => JS_LIBRARY, 'weight' => -99, 'every_page' => TRUE, 'scope' => 'header'));
    drupal_add_js('misc/jquery.cookie.js', array('group' => JS_LIBRARY, 'weight' => -98, 'every_page' => TRUE, 'scope' => 'header'));
    drupal_add_js('misc/form.js', array('weight' => 19, 'every_page' => TRUE, 'scope' => 'header'));
    drupal_add_js('misc/collapse.js', array('weight' => 20, 'every_page' => TRUE, 'scope' => 'header'));
}

The only core JS file loading by itself is drupal.js, and a bunch of module scripts. Other than that I had to include the 5 above myself, otherwise various parts of the public site and admin areas were not working.

This works, but it feels really sketchy. And previously I had only included the first 3, until I noticed more admin form stuff breaking. So I hate to think that there may be MORE scripts that I will only discover missing through trial and error.

Any ideas why they are not being included??

UPDATE

I've narrowed it down, there are two custom modules which are breaking it. One of them is much simpler than the other so I'll just try to figure that one out first. This line of code, inside the .module file, and not within any function, is causing the issue ($form_js is a string containing JavaScript)

drupal_add_js($form_js, array('type' => 'inline', 'scope' => 'footer'));
7
  • I noticed that on another admin import page, progress.js and batch.js were not being included. -_- What is going on?!
    – user11312
    Commented Aug 30, 2013 at 21:59
  • Any errors on the browser's log or drupal recent log? It happend after installing a new module or code modificaton?
    – rreiss
    Commented Aug 30, 2013 at 23:58
  • @Rotem no errors in the recent log. There were errors in the JS console because the files were not being included, jQuery was not defined, etc. After I manually added the JS files in, no console errors either
    – user11312
    Commented Aug 31, 2013 at 1:02
  • @Rotem unfortunately I am coming into this project after someone else has built most of it, so I couldn't say when or what module may have caused it. Maybe my best bet is to disable modules one at a time :/
    – user11312
    Commented Aug 31, 2013 at 1:03
  • If you have devel installed, try to use dpm($js); on the begining of your implementation of hook_js_alter() and see if the files exists in that array.
    – rreiss
    Commented Aug 31, 2013 at 12:14

1 Answer 1

1

I figured out that using drupal_add_js outside of a hook_js_alter function in another file was causing the issue.

drupal_add_js($form_js, array('type' => 'inline', 'scope' => 'footer'));

Now that it is within the function, it's working fine.

I don't see anything in the documentation saying that this is required -> also, drupal_add_css works fine outside of a function. I'm not altering any existing JS files, only adding new ones.

So while I don't understand why this is an issue, this is the solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.