AlertCommand.php 647 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Drupal\Core\Ajax;
  3. /**
  4. * AJAX command for a javascript alert box.
  5. *
  6. * @ingroup ajax
  7. */
  8. class AlertCommand implements CommandInterface {
  9. /**
  10. * The text to be displayed in the alert box.
  11. *
  12. * @var string
  13. */
  14. protected $text;
  15. /**
  16. * Constructs an AlertCommand object.
  17. *
  18. * @param string $text
  19. * The text to be displayed in the alert box.
  20. */
  21. public function __construct($text) {
  22. $this->text = $text;
  23. }
  24. /**
  25. * Implements Drupal\Core\Ajax\CommandInterface:render().
  26. */
  27. public function render() {
  28. return [
  29. 'command' => 'alert',
  30. 'text' => $this->text,
  31. ];
  32. }
  33. }