1. 8.5.x core/lib/Drupal/Core/Ajax/SettingsCommand.php SettingsCommand
  2. 8.0.x core/lib/Drupal/Core/Ajax/SettingsCommand.php SettingsCommand
  3. 8.1.x core/lib/Drupal/Core/Ajax/SettingsCommand.php SettingsCommand
  4. 8.2.x core/lib/Drupal/Core/Ajax/SettingsCommand.php SettingsCommand
  5. 8.3.x core/lib/Drupal/Core/Ajax/SettingsCommand.php SettingsCommand
  6. 8.4.x core/lib/Drupal/Core/Ajax/SettingsCommand.php SettingsCommand
  7. 8.6.x core/lib/Drupal/Core/Ajax/SettingsCommand.php SettingsCommand

AJAX command for adjusting Drupal's JavaScript settings.

The 'settings' command instructs the client either to use the given array as the settings for ajax-loaded content or to extend drupalSettings with the given array, depending on the value of the $merge parameter.

This command is implemented by Drupal.AjaxCommands.prototype.settings() defined in misc/ajax.js.

Hierarchy

Expanded class hierarchy of SettingsCommand

Related topics

4 files declare their use of SettingsCommand
AjaxCommandsTest.php in core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php
ajax_forms_test.module in core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module
Simpletest mock module for Ajax forms testing.
CommandsTest.php in core/modules/system/src/Tests/Ajax/CommandsTest.php
FrameworkTest.php in core/modules/system/src/Tests/Ajax/FrameworkTest.php

File

core/lib/Drupal/Core/Ajax/SettingsCommand.php, line 17

Namespace

Drupal\Core\Ajax
View source
class SettingsCommand implements CommandInterface {

  /**
   * An array of key/value pairs of JavaScript settings.
   *
   * This will be used for all commands after this if they do not include their
   * own settings array.
   *
   * @var array
   */
  protected $settings;

  /**
   * Whether the settings should be merged into the global drupalSettings.
   *
   * By default (FALSE), the settings that are passed to Drupal.attachBehaviors
   * will not include the global drupalSettings.
   *
   * @var bool
   */
  protected $merge;

  /**
   * Constructs a SettingsCommand object.
   *
   * @param array $settings
   *   An array of key/value pairs of JavaScript settings.
   * @param bool $merge
   *   Whether the settings should be merged into the global drupalSettings.
   */
  public function __construct(array $settings, $merge = FALSE) {
    $this->settings = $settings;
    $this->merge = $merge;
  }

  /**
   * Implements Drupal\Core\Ajax\CommandInterface:render().
   */
  public function render() {
    return [
      'command' => 'settings',
      'settings' => $this->settings,
      'merge' => $this->merge,
    ];
  }

}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description Overrides
SettingsCommand::$merge protected property Whether the settings should be merged into the global drupalSettings.
SettingsCommand::$settings protected property An array of key/value pairs of JavaScript settings.
SettingsCommand::render public function Implements Drupal\Core\Ajax\CommandInterface:render(). Overrides CommandInterface::render
SettingsCommand::__construct public function Constructs a SettingsCommand object.