annotate core/modules/settings_tray/src/Ajax/OpenOffCanvasDialogCommand.php @ 0:4c8ae668cc8c

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