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