3 namespace Drupal\settings_tray\Ajax;
5 use Drupal\Core\Ajax\OpenDialogCommand;
8 * Defines an AJAX command to open content in a dialog in a off-canvas dialog.
14 class OpenOffCanvasDialogCommand extends OpenDialogCommand {
17 * The dialog width to use if none is provided.
19 const DEFAULT_DIALOG_WIDTH = 300;
22 * Constructs an OpenOffCanvasDialogCommand object.
24 * The off-canvas dialog differs from the normal modal provided by
25 * OpenDialogCommand in that a off-canvas has built in positioning and
26 * behaviours. Drupal provides a built-in off-canvas dialog for this purpose,
27 * so the selector is hard-coded in the call to the parent constructor.
29 * @param string $title
30 * The title of the dialog.
31 * @param string|array $content
32 * The content that will be placed in the dialog, either a render array
34 * @param array $dialog_options
35 * (optional) Settings to be passed to the dialog implementation. Any
36 * jQuery UI option can be used. See http://api.jqueryui.com/dialog.
37 * @param array|null $settings
38 * (optional) Custom settings that will be passed to the Drupal behaviors
39 * on the content of the dialog. If left empty, the settings will be
40 * populated automatically from the current request.
42 public function __construct($title, $content, array $dialog_options = [], $settings = NULL) {
43 parent::__construct('#drupal-off-canvas', $title, $content, $dialog_options, $settings);
44 $this->dialogOptions['modal'] = FALSE;
45 $this->dialogOptions['autoResize'] = FALSE;
46 $this->dialogOptions['resizable'] = 'w';
47 $this->dialogOptions['draggable'] = FALSE;
48 $this->dialogOptions['drupalAutoButtons'] = FALSE;
49 // @todo drupal.ajax.js does not respect drupalAutoButtons properly, pass an
50 // empty set of buttons until https://www.drupal.org/node/2793343 is in.
51 $this->dialogOptions['buttons'] = [];
52 if (empty($dialog_options['dialogClass'])) {
53 $this->dialogOptions['dialogClass'] = 'ui-dialog-off-canvas';
55 // If no width option is provided then use the default width to avoid the
56 // dialog staying at the width of the previous instance when opened
57 // more than once, with different widths, on a single page.
58 if (!isset($this->dialogOptions['width'])) {
59 $this->dialogOptions['width'] = static::DEFAULT_DIALOG_WIDTH;
66 public function render() {
67 $build = parent::render();
68 $build['effect'] = 'fade';
69 $build['speed'] = 1000;