Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / settings_tray / src / Ajax / OpenOffCanvasDialogCommand.php
1 <?php
2
3 namespace Drupal\settings_tray\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  * @internal
13  */
14 class OpenOffCanvasDialogCommand extends OpenDialogCommand {
15
16   /**
17    * The dialog width to use if none is provided.
18    */
19   const DEFAULT_DIALOG_WIDTH = 300;
20
21   /**
22    * Constructs an OpenOffCanvasDialogCommand object.
23    *
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.
28    *
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
33    *   or an HTML string.
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.
41    */
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';
54     }
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;
60     }
61   }
62
63   /**
64    * {@inheritdoc}
65    */
66   public function render() {
67     $build = parent::render();
68     $build['effect'] = 'fade';
69     $build['speed'] = 1000;
70     return $build;
71   }
72
73 }