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

AJAX command for invoking an arbitrary jQuery method.

The 'invoke' command will instruct the client to invoke the given jQuery method with the supplied arguments on the elements matched by the given selector. Intended for simple jQuery commands, such as attr(), addClass(), removeClass(), toggleClass(), etc.

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

Hierarchy

Expanded class hierarchy of InvokeCommand

Related topics

3 files declare their use of InvokeCommand
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

File

core/lib/Drupal/Core/Ajax/InvokeCommand.php, line 18

Namespace

Drupal\Core\Ajax
View source
class InvokeCommand 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;

  /**
   * A jQuery method to invoke.
   *
   * @var string
   */
  protected $method;

  /**
   * An optional list of arguments to pass to the method.
   *
   * @var array
   */
  protected $arguments;

  /**
   * Constructs an InvokeCommand object.
   *
   * @param string $selector
   *   A jQuery selector.
   * @param string $method
   *   The name of a jQuery method to invoke.
   * @param array $arguments
   *   An optional array of arguments to pass to the method.
   */
  public function __construct($selector, $method, array $arguments = []) {
    $this->selector = $selector;
    $this->method = $method;
    $this->arguments = $arguments;
  }

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

}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description Overrides
InvokeCommand::$arguments protected property An optional list of arguments to pass to the method.
InvokeCommand::$method protected property A jQuery method to invoke.
InvokeCommand::$selector protected property A CSS selector string.
InvokeCommand::render public function Implements Drupal\Core\Ajax\CommandInterface:render(). Overrides CommandInterface::render
InvokeCommand::__construct public function Constructs an InvokeCommand object.