ChangedCommand.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Drupal\Core\Ajax;
  3. /**
  4. * An AJAX command for marking HTML elements as changed.
  5. *
  6. * This command instructs the client to mark each of the elements matched by the
  7. * given selector as 'ajax-changed'.
  8. *
  9. * This command is implemented by Drupal.AjaxCommands.prototype.changed()
  10. * defined in misc/ajax.js.
  11. *
  12. * @ingroup ajax
  13. */
  14. class ChangedCommand implements CommandInterface {
  15. /**
  16. * A CSS selector string.
  17. *
  18. * If the command is a response to a request from an #ajax form element then
  19. * this value can be NULL.
  20. *
  21. * @var string
  22. */
  23. protected $selector;
  24. /**
  25. * An optional CSS selector for elements to which asterisks will be appended.
  26. *
  27. * @var string
  28. */
  29. protected $asterisk;
  30. /**
  31. * Constructs a ChangedCommand object.
  32. *
  33. * @param string $selector
  34. * CSS selector for elements to be marked as changed.
  35. * @param string $asterisk
  36. * CSS selector for elements to which an asterisk will be appended.
  37. */
  38. public function __construct($selector, $asterisk = '') {
  39. $this->selector = $selector;
  40. $this->asterisk = $asterisk;
  41. }
  42. /**
  43. * Implements Drupal\Core\Ajax\CommandInterface:render().
  44. */
  45. public function render() {
  46. return [
  47. 'command' => 'changed',
  48. 'selector' => $this->selector,
  49. 'asterisk' => $this->asterisk,
  50. ];
  51. }
  52. }