Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

In order to reduce the dependency on jQuery (and in particular the need for deep object merging like with $.extend), the Drupal.settings object was given its own top-level namespace, namely drupalSettings and Drupal.settings has been removed.

Practically this changes:

  • In the HTML source, drupalSettings is printed before all other JS script on the page.
  • drupalSettings is available right away, no need to wait for an attach behavior to be called.

The library name for hook_library_info was changed from drupal.settings to drupalSettings to reflect the change on the javascript side.

PHP side

Before

  // Drupal's progress indicator.
  $libraries['drupal.progress'] = array(
    'title' => 'Drupal progress indicator',
    'version' => VERSION,
    'js' => array(
      'core/misc/progress.js' => array('group' => JS_DEFAULT),
    ),
    'dependencies' => array(
      array('system', 'drupal'),
      array('system', 'jquery'),
      array('system', 'drupal.settings'),
    ),
  );

After

  // Drupal's progress indicator.
  $libraries['drupal.progress'] = array(
    'title' => 'Drupal progress indicator',
    'version' => VERSION,
    'js' => array(
      'core/misc/progress.js' => array('group' => JS_DEFAULT),
    ),
    'dependencies' => array(
      array('system', 'drupal'),
      array('system', 'jquery'),
      array('system', 'drupalSettings'),
    ),
  );

JS side

Before

(function ($, Drupal) {

Drupal.behaviors.myBehavior = {
  attach: function (context, settings) {
    // can access setting from 'settings' or 'Drupal.settings';
  }
};

})(jQuery, Drupal);

After

(function ($, Drupal, drupalSettings) {

// At this point 'drupalSettings' is already available.

})(jQuery, Drupal, drupalSettings);
Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done

Comments

arnoldbird’s picture

Are the "Before" and "After" on the PHP side supposed to be identical, or is that a mistake?

brianwagner’s picture

@arnoldbird There is one difference. New value is "drupalSettings"