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