class InsertCommand

Generic AJAX command for inserting content.

This command instructs the client to insert the given HTML using whichever jQuery DOM manipulation method has been specified in the #ajax['method'] variable of the element that triggered the request.

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

Hierarchy

Expanded class hierarchy of InsertCommand

9 files declare their use of InsertCommand
AfterCommand.php in drupal/core/lib/Drupal/Core/Ajax/AfterCommand.php
Definition of Drupal\Core\Ajax\AfterCommand.
AjaxCommandsUnitTest.php in drupal/core/modules/system/lib/Drupal/system/Tests/Ajax/AjaxCommandsUnitTest.php
Definition of Drupal\system\Tests\Ajax\AjaxCommandsUnitTest.
AjaxController.php in drupal/core/lib/Drupal/Core/Controller/AjaxController.php
Contains \Drupal\Core\Controller\AjaxController.
AppendCommand.php in drupal/core/lib/Drupal/Core/Ajax/AppendCommand.php
Definition of Drupal\Core\Ajax\AppendCommand.
BeforeCommand.php in drupal/core/lib/Drupal/Core/Ajax/BeforeCommand.php
Definition of Drupal\Core\Ajax\InsertCommand.

... See full list

File

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

Namespace

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

  /**
   * A CSS selector string.
   *
   * 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 HTML content that will replace the matched element(s).
   *
   * @var string
   */
  protected $html;

  /**
   * A settings array to be passed to any any attached JavaScript behavior.
   *
   * @var array
   */
  protected $settings;

  /**
   * Constructs an InsertCommand object.
   *
   * @param string $selector
   *   A CSS selector.
   * @param string $html
   *   String of HTML that will replace the matched element(s).
   * @param array $settings
   *   An array of JavaScript settings to be passed to any attached behaviors.
   */
  public function __construct($selector, $html, array $settings = NULL) {
    $this->selector = $selector;
    $this->html = $html;
    $this->settings = $settings;
  }

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

}

Members

Namesort descending Modifiers Type Description Overrides
InsertCommand::$html protected property The HTML content that will replace the matched element(s).
InsertCommand::$selector protected property A CSS selector string.
InsertCommand::$settings protected property A settings array to be passed to any any attached JavaScript behavior.
InsertCommand::render public function Implements Drupal\Core\Ajax\CommandInterface:render(). Overrides CommandInterface::render 6
InsertCommand::__construct public function Constructs an InsertCommand object.