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

An AJAX command for implementing jQuery's data() method.

This instructs the client to attach the name=value pair of data to the selector via jQuery's data cache.

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

Hierarchy

Expanded class hierarchy of DataCommand

Related topics

5 files declare their use of DataCommand
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.
Callbacks.php in core/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php
CommandsTest.php in core/modules/system/src/Tests/Ajax/CommandsTest.php
FormValuesTest.php in core/modules/system/src/Tests/Ajax/FormValuesTest.php

File

core/lib/Drupal/Core/Ajax/DataCommand.php, line 16

Namespace

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

  /**
   * A CSS selector string for elements to which data will be attached.
   *
   * If the command is a response to a request from an #ajax form element then
   * this value can be NULL.
   *
   * @var string
   */
  protected $selector;

  /**
   * The key of the data attached to elements matched by the selector.
   *
   * @var string
   */
  protected $name;

  /**
   * The value of the data to be attached to elements matched by the selector.
   *
   * The data is not limited to strings; it can be any format.
   *
   * @var mixed
   */
  protected $value;

  /**
   * Constructs a DataCommand object.
   *
   * @param string $selector
   *   A CSS selector for the elements to which the data will be attached.
   * @param string $name
   *   The key of the data to be attached to elements matched by the selector.
   * @param mixed $value
   *   The value of the data to be attached to elements matched by the selector.
   */
  public function __construct($selector, $name, $value) {
    $this->selector = $selector;
    $this->name = $name;
    $this->value = $value;
  }

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

}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description Overrides
DataCommand::$name protected property The key of the data attached to elements matched by the selector.
DataCommand::$selector protected property A CSS selector string for elements to which data will be attached.
DataCommand::$value protected property The value of the data to be attached to elements matched by the selector.
DataCommand::render public function Implements Drupal\Core\Ajax\CommandInterface:render(). Overrides CommandInterface::render
DataCommand::__construct public function Constructs a DataCommand object.