Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By nod_ on
Change record status:
Published (View all published change records)
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
Comments
Are the "Before" and "After"
Are the "Before" and "After" on the PHP side supposed to be identical, or is that a mistake?
Variable name drupalSettings
@arnoldbird There is one difference. New value is "drupalSettings"