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