class 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 Drupal.settings with the given array, depending on the value of the $merge parameter.

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

Hierarchy

Expanded class hierarchy of SettingsCommand

1 file declares its use of SettingsCommand
AjaxCommandsUnitTest.php in drupal/core/modules/system/lib/Drupal/system/Tests/Ajax/AjaxCommandsUnitTest.php
Definition of Drupal\system\Tests\Ajax\AjaxCommandsUnitTest.

File

drupal/core/lib/Drupal/Core/Ajax/SettingsCommand.php, line 22
Definition of Drupal\Core\Ajax\SettingsCommand.

Namespace

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

  /**
   * An array of key/value pairs of JavaScript settings.
   *
   * This will be utilized 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 Drupal.settings.
   *
   * By default (FALSE), the settings that are passed to Drupal.attachBehaviors
   * will not include the global Drupal.settings.
   *
   * @var boolean
   */
  protected $merge;

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

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

}

Members

Namesort descending Modifiers Type Description Overrides
SettingsCommand::$merge protected property Whether the settings should be merged into the global Drupal.settings.
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.