annotate core/lib/Drupal/Core/Ajax/DataCommand.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 * An AJAX command for implementing jQuery's data() method.
Chris@0 7 *
Chris@0 8 * This instructs the client to attach the name=value pair of data to the
Chris@0 9 * selector via jQuery's data cache.
Chris@0 10 *
Chris@0 11 * This command is implemented by Drupal.AjaxCommands.prototype.data() defined
Chris@0 12 * in misc/ajax.js.
Chris@0 13 *
Chris@0 14 * @ingroup ajax
Chris@0 15 */
Chris@0 16 class DataCommand implements CommandInterface {
Chris@0 17
Chris@0 18 /**
Chris@0 19 * A CSS selector string for elements to which data will be attached.
Chris@0 20 *
Chris@0 21 * If the command is a response to a request from an #ajax form element then
Chris@0 22 * this value can be NULL.
Chris@0 23 *
Chris@0 24 * @var string
Chris@0 25 */
Chris@0 26 protected $selector;
Chris@0 27
Chris@0 28 /**
Chris@0 29 * The key of the data attached to elements matched by the selector.
Chris@0 30 *
Chris@0 31 * @var string
Chris@0 32 */
Chris@0 33 protected $name;
Chris@0 34
Chris@0 35 /**
Chris@0 36 * The value of the data to be attached to elements matched by the selector.
Chris@0 37 *
Chris@0 38 * The data is not limited to strings; it can be any format.
Chris@0 39 *
Chris@0 40 * @var mixed
Chris@0 41 */
Chris@0 42 protected $value;
Chris@0 43
Chris@0 44 /**
Chris@0 45 * Constructs a DataCommand object.
Chris@0 46 *
Chris@0 47 * @param string $selector
Chris@0 48 * A CSS selector for the elements to which the data will be attached.
Chris@0 49 * @param string $name
Chris@0 50 * The key of the data to be attached to elements matched by the selector.
Chris@0 51 * @param mixed $value
Chris@0 52 * The value of the data to be attached to elements matched by the selector.
Chris@0 53 */
Chris@0 54 public function __construct($selector, $name, $value) {
Chris@0 55 $this->selector = $selector;
Chris@0 56 $this->name = $name;
Chris@0 57 $this->value = $value;
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' => 'data',
Chris@0 67 'selector' => $this->selector,
Chris@0 68 'name' => $this->name,
Chris@0 69 'value' => $this->value,
Chris@0 70 ];
Chris@0 71 }
Chris@0 72
Chris@0 73 }