CloseDialogCommand.php 1001 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Drupal\Core\Ajax;
  3. /**
  4. * Defines an AJAX command that closes the current active dialog.
  5. *
  6. * @ingroup ajax
  7. */
  8. class CloseDialogCommand implements CommandInterface {
  9. /**
  10. * A CSS selector string of the dialog to close.
  11. *
  12. * @var string
  13. */
  14. protected $selector;
  15. /**
  16. * Whether to persist the dialog in the DOM or not.
  17. *
  18. * @var bool
  19. */
  20. protected $persist;
  21. /**
  22. * Constructs a CloseDialogCommand object.
  23. *
  24. * @param string $selector
  25. * A CSS selector string of the dialog to close.
  26. * @param bool $persist
  27. * (optional) Whether to persist the dialog in the DOM or not.
  28. */
  29. public function __construct($selector = NULL, $persist = FALSE) {
  30. $this->selector = $selector ? $selector : '#drupal-modal';
  31. $this->persist = $persist;
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function render() {
  37. return [
  38. 'command' => 'closeDialog',
  39. 'selector' => $this->selector,
  40. 'persist' => $this->persist,
  41. ];
  42. }
  43. }