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