If I use the following code in template.php
$options = array(
'css' => array($type = 'theme', $media = 'all', $preprocess = TRUE),
'js' => array($type = 'theme', $scope = 'header', $defer = FALSE, $cache = TRUE, $preprocess = TRUE),
);
drupal_add_js_library('scrolltotop', '1', $options);
I get following warnings
* warning: Illegal offset type in isset or empty in includes\common.inc on line 2127.
* warning: Illegal offset type in includes\common.inc on line 2128.
* warning: Illegal offset type in includes\common.inc on line 2140.
* warning: Illegal offset type in isset or empty in includes\common.inc on line 2127.
* warning: Illegal offset type in includes\common.inc on line 2128.
* warning: Illegal offset type in includes\common.inc on line 2140.
* warning: Illegal offset type in includes\common.inc on line 1794.
but if I use the following code everything works as expected
drupal_add_js_library('scrolltotop', '1', $options);
which means options are passed with default values
what does it seem to be the problem ?
Comments
Comment #1
skilip commentedSorry for really, really late responding. Still experiencing this issue?
Comment #2
skilip commentedComment #3
Matt-H commentedI have run into this problem as well. Fortunately, I have a fix (see the bottom of my post).
Let's say your in your library, your component files look like this:
(which is what $files arrray looks like in drupal_add_library() after the file types are looped through)
And let's use the $options in the above example:
In drupal_add_library(), the paths from the $files array get merged with the $options, and the resulting arrays look like this:
It is merging the path with the entire $options array, causing the drupal_add_js and drupal_add_css to fail when that array is passed to them. (That's why the defaults work and passing an $options does not).
Instead, the arrays need to look like this:
The drupal_add_library() needs modifying, changing how it is merges the whole $options with the $path.
lines 278-282
This should be:
I hope this helps!
Comment #4
Matt-H commentedI am adding a patch that should fix the problem with submitting $options into drupal_add_library().
Edit: Oops. I have a problem with the names in the patch. My apologies. I will upload a fixed patch.
Comment #5
Matt-H commentedHere is a fixed and tested version of the patch. (The old one may be removed.) Please review at your convenience.
Comment #6
skilip commentedHi Matt-H, Thanks for your patch! It looks rather straightforward, so marking this RTBC so it'll get included in the next release. Thanks again!
Comment #7
skilip commented