3 namespace Drupal\Core\Ajax;
6 * AJAX command for adjusting Drupal's JavaScript settings.
8 * The 'settings' command instructs the client either to use the given array as
9 * the settings for ajax-loaded content or to extend drupalSettings with the
10 * given array, depending on the value of the $merge parameter.
12 * This command is implemented by Drupal.AjaxCommands.prototype.settings()
13 * defined in misc/ajax.js.
17 class SettingsCommand implements CommandInterface {
20 * An array of key/value pairs of JavaScript settings.
22 * This will be used for all commands after this if they do not include their
30 * Whether the settings should be merged into the global drupalSettings.
32 * By default (FALSE), the settings that are passed to Drupal.attachBehaviors
33 * will not include the global drupalSettings.
40 * Constructs a SettingsCommand object.
42 * @param array $settings
43 * An array of key/value pairs of JavaScript settings.
45 * Whether the settings should be merged into the global drupalSettings.
47 public function __construct(array $settings, $merge = FALSE) {
48 $this->settings = $settings;
49 $this->merge = $merge;
53 * Implements Drupal\Core\Ajax\CommandInterface:render().
55 public function render() {
58 'command' => 'settings',
59 'settings' => $this->settings,
60 'merge' => $this->merge,