annotate core/lib/Drupal/Core/Ajax/InvokeCommand.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Core\Ajax;
Chris@0 4
Chris@0 5 /**
Chris@0 6 * AJAX command for invoking an arbitrary jQuery method.
Chris@0 7 *
Chris@0 8 * The 'invoke' command will instruct the client to invoke the given jQuery
Chris@0 9 * method with the supplied arguments on the elements matched by the given
Chris@0 10 * selector. Intended for simple jQuery commands, such as attr(), addClass(),
Chris@0 11 * removeClass(), toggleClass(), etc.
Chris@0 12 *
Chris@0 13 * This command is implemented by Drupal.AjaxCommands.prototype.invoke()
Chris@0 14 * defined in misc/ajax.js.
Chris@0 15 *
Chris@0 16 * @ingroup ajax
Chris@0 17 */
Chris@0 18 class InvokeCommand implements CommandInterface {
Chris@0 19
Chris@0 20 /**
Chris@0 21 * A CSS selector string.
Chris@0 22 *
Chris@0 23 * If the command is a response to a request from an #ajax form element then
Chris@0 24 * this value can be NULL.
Chris@0 25 *
Chris@0 26 * @var string
Chris@0 27 */
Chris@0 28 protected $selector;
Chris@0 29
Chris@0 30 /**
Chris@0 31 * A jQuery method to invoke.
Chris@0 32 *
Chris@0 33 * @var string
Chris@0 34 */
Chris@0 35 protected $method;
Chris@0 36
Chris@0 37 /**
Chris@0 38 * An optional list of arguments to pass to the method.
Chris@0 39 *
Chris@0 40 * @var array
Chris@0 41 */
Chris@0 42 protected $arguments;
Chris@0 43
Chris@0 44 /**
Chris@0 45 * Constructs an InvokeCommand object.
Chris@0 46 *
Chris@0 47 * @param string $selector
Chris@0 48 * A jQuery selector.
Chris@0 49 * @param string $method
Chris@0 50 * The name of a jQuery method to invoke.
Chris@0 51 * @param array $arguments
Chris@0 52 * An optional array of arguments to pass to the method.
Chris@0 53 */
Chris@0 54 public function __construct($selector, $method, array $arguments = []) {
Chris@0 55 $this->selector = $selector;
Chris@0 56 $this->method = $method;
Chris@0 57 $this->arguments = $arguments;
Chris@0 58 }
Chris@0 59
Chris@0 60 /**
Chris@0 61 * Implements Drupal\Core\Ajax\CommandInterface:render().
Chris@0 62 */
Chris@0 63 public function render() {
Chris@0 64
Chris@0 65 return [
Chris@0 66 'command' => 'invoke',
Chris@0 67 'selector' => $this->selector,
Chris@0 68 'method' => $this->method,
Chris@0 69 'args' => $this->arguments,
Chris@0 70 ];
Chris@0 71 }
Chris@0 72
Chris@0 73 }