CloseDialogCommand.php 1.05 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
<?php

/**
 * @file
 * Contains \Drupal\Core\Ajax\CloseDialogCommand.
 */

namespace Drupal\Core\Ajax;

/**
 * Defines an AJAX command that closes the current active dialog.
12 13
 *
 * @ingroup ajax
14 15 16 17 18 19 20 21 22 23
 */
class CloseDialogCommand implements CommandInterface {

  /**
   * A CSS selector string of the dialog to close.
   *
   * @var string
   */
  protected $selector;

24 25 26 27 28 29 30
  /**
   * Whether to persist the dialog in the DOM or not.
   *
   * @var bool
   */
  protected $persist;

31 32 33 34 35
  /**
   * Constructs a CloseDialogCommand object.
   *
   * @param string $selector
   *   A CSS selector string of the dialog to close.
36 37
   * @param bool $persist
   *   (optional) Whether to persist the dialog in the DOM or not.
38
   */
39
  public function __construct($selector = NULL, $persist = FALSE) {
40
    $this->selector = $selector ? $selector : '#drupal-modal';
41
    $this->persist = $persist;
42 43 44
  }

  /**
45
   * {@inheritdoc}
46 47 48 49 50
   */
  public function render() {
    return array(
      'command' => 'closeDialog',
      'selector' => $this->selector,
51
      'persist' => $this->persist,
52 53 54
    );
  }
}