Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/Ajax/DataCommand.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Core\Ajax; | |
4 | |
5 /** | |
6 * An AJAX command for implementing jQuery's data() method. | |
7 * | |
8 * This instructs the client to attach the name=value pair of data to the | |
9 * selector via jQuery's data cache. | |
10 * | |
11 * This command is implemented by Drupal.AjaxCommands.prototype.data() defined | |
12 * in misc/ajax.js. | |
13 * | |
14 * @ingroup ajax | |
15 */ | |
16 class DataCommand implements CommandInterface { | |
17 | |
18 /** | |
19 * A CSS selector string for elements to which data will be attached. | |
20 * | |
21 * If the command is a response to a request from an #ajax form element then | |
22 * this value can be NULL. | |
23 * | |
24 * @var string | |
25 */ | |
26 protected $selector; | |
27 | |
28 /** | |
29 * The key of the data attached to elements matched by the selector. | |
30 * | |
31 * @var string | |
32 */ | |
33 protected $name; | |
34 | |
35 /** | |
36 * The value of the data to be attached to elements matched by the selector. | |
37 * | |
38 * The data is not limited to strings; it can be any format. | |
39 * | |
40 * @var mixed | |
41 */ | |
42 protected $value; | |
43 | |
44 /** | |
45 * Constructs a DataCommand object. | |
46 * | |
47 * @param string $selector | |
48 * A CSS selector for the elements to which the data will be attached. | |
49 * @param string $name | |
50 * The key of the data to be attached to elements matched by the selector. | |
51 * @param mixed $value | |
52 * The value of the data to be attached to elements matched by the selector. | |
53 */ | |
54 public function __construct($selector, $name, $value) { | |
55 $this->selector = $selector; | |
56 $this->name = $name; | |
57 $this->value = $value; | |
58 } | |
59 | |
60 /** | |
61 * Implements Drupal\Core\Ajax\CommandInterface:render(). | |
62 */ | |
63 public function render() { | |
64 | |
65 return [ | |
66 'command' => 'data', | |
67 'selector' => $this->selector, | |
68 'name' => $this->name, | |
69 'value' => $this->value, | |
70 ]; | |
71 } | |
72 | |
73 } |