This patch does what the title says. This allows for the possibility of ultimately allowing the option to override function parameters for #315100: Allow to add JS/CSS libraries (sets of files, settings, and dependent libraries).

That means that to reset js, you'll call drupal_add_js(NULL, 'reset'); rather than drupal_add_js(NULL, NULL, TRUE);

For completeness, we do the same with drupal_add_css. (Hoping we can merge those two functions later for cleaner code.) This patch also takes care of all simpletests for the two. I grepped core for drupal_add_js(NULL, NULL, TRUE); and drupal_add_css(NULL, NULL, TRUE); but found nothing.

There's also the possibility that something like drupal_add_js('myfile.js', 'header', TRUE); is called, which would be bad practice now. I did a quick scan through the API and didn't see anything, so it's probably safe.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

RobLoach’s picture

Status: Active » Needs work

This is wicked awesome cool, but noticed this:

-function drupal_add_css($path = NULL, $options = NULL, $reset = FALSE) {
-  static $css = array();
+function drupal_add_css($path = NULL, $options = NULL) {
+static $css = array();

Would be good to have the two spaces in there. I'll be able to hit this up sometime in the next 12 hours.

aaron’s picture

Status: Needs work » Needs review
FileSize
6.36 KB

thanks for catching that. here's an updated patch.

RobLoach’s picture

Status: Needs review » Reviewed & tested by the community

Yay!

RobLoach’s picture

FileSize
5.91 KB

Sorry, thought I should remove the fuzzies. Didn't change anything code-wise.

quicksketch’s picture

Status: Reviewed & tested by the community » Needs work

Hrm, it seems to me that the documentation for the 'reset' parameter is inaccurate.

+ *   Note that if $options or $options['type'] is 'reset', then $path will be
+ *   ignored.

This doesn't seem to be the case, the processing continues even after the reset. So you could in theory add CSS/JS file at the same time as resetting all the current files. Should we add a "return" immediately following the if (options['reset']) or should we adjust the docs? The $options['reset'] option also needs a much better description, since it doesn't say what it actually does.

RobLoach’s picture

Status: Needs work » Needs review
FileSize
5.96 KB

Note that if type is 'reset', then $data and all other $options will be ignored and the JavaScript added so far will be reset.

mfer’s picture

Status: Needs review » Reviewed & tested by the community

Code looks good. Tests pass. This is a simple change.

RobLoach’s picture

FileSize
6.3 KB

Webchick asked for a test.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

Awesome, thanks!!

Committed to HEAD. This needs documentation in the upgrade docs, it looks like.

RobLoach’s picture

Yay, thanks a lot, Matt and Aaron. Docs here, if there's anything missing there, please feel free to hack away.

RobLoach’s picture

Status: Needs work » Fixed

Uhh, fixed. Next step is #259368: Allow Inline CSS in drupal_add_css, I believe.....

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.