Settings has group -100 like jquery and weight 0
It must be placed after jquery.once.js, not after all scripts

If the correct order, I can use the data from the settings in all my scripts without waiting for the event document.ready

CommentFileSizeAuthor
#8 1710002-8.patch688 bytesstar-szr
#1 common.inc_.patch726 bytesPunk_UnDeaD
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Punk_UnDeaD’s picture

FileSize
726 bytes
--- includes/common.inc	(revision )
+++ includes/common.inc	(revision )
@@ -4233,7 +4233,7 @@
         $js_element['#value_prefix'] = $embed_prefix;
         $js_element['#value'] = 'jQuery.extend(Drupal.settings, ' . drupal_json_encode(drupal_array_merge_deep_array($item['data'])) . ");";
         $js_element['#value_suffix'] = $embed_suffix;
-        $output .= theme('html_tag', array('element' => $js_element));
+        $processed[$index++] = theme('html_tag', array('element' => $js_element));
         break;
 
       case 'inline':
dealancer’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, common.inc_.patch, failed testing.

nod_’s picture

Version: 7.x-dev » 8.x-dev

I tend to agree with this.

Needs to be fixed in D8 first then backported.

nod_’s picture

Status: Needs work » Fixed

Weight is now -200 on D8 for settings.

dealancer’s picture

Whoohoo, was it committed or solved in other issue?

Status: Fixed » Closed (fixed)

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

star-szr’s picture

Title: Correct order for js settings » Correct weight for JS Drupal.settings
Version: 8.x-dev » 7.x-dev
Category: feature » bug
Status: Closed (fixed) » Needs review
FileSize
688 bytes

Re-opening, this is a bug and can still be fixed in D7. Ran into this when trying to use Drupal.settings in JavaScript included via a theme's .info file.

An inline comment in drupal_add_js() states:

// All JavaScript settings are placed in the header of the page with
// the library weight so that inline scripts appear afterwards.
star-szr’s picture

Title: Correct weight for JS Drupal.settings » Weight is not set for Drupal.settings JavaScript
star-szr’s picture

#8: 1710002-8.patch queued for re-testing.

nod_’s picture

If you try accessing settings outside a behaviour or before the ready jquery thing. All bets are off.

star-szr’s picture

Thanks @nod_. Fair enough :) So won't fix for D7?

nod_’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs review » Closed (fixed)

For D7, pretty much, yes :)