annotate core/lib/Drupal/Core/Ajax/OpenOffCanvasDialogCommand.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
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@17 37 * @param string $position
Chris@17 38 * (optional) The position to render the off-canvas dialog.
Chris@14 39 */
Chris@17 40 public function __construct($title, $content, array $dialog_options = [], $settings = NULL, $position = 'side') {
Chris@14 41 parent::__construct('#drupal-off-canvas', $title, $content, $dialog_options, $settings);
Chris@14 42 $this->dialogOptions['modal'] = FALSE;
Chris@14 43 $this->dialogOptions['autoResize'] = FALSE;
Chris@14 44 $this->dialogOptions['resizable'] = 'w';
Chris@14 45 $this->dialogOptions['draggable'] = FALSE;
Chris@14 46 $this->dialogOptions['drupalAutoButtons'] = FALSE;
Chris@17 47 $this->dialogOptions['drupalOffCanvasPosition'] = $position;
Chris@14 48 // @todo drupal.ajax.js does not respect drupalAutoButtons properly, pass an
Chris@14 49 // empty set of buttons until https://www.drupal.org/node/2793343 is in.
Chris@14 50 $this->dialogOptions['buttons'] = [];
Chris@14 51 if (empty($dialog_options['dialogClass'])) {
Chris@17 52 $this->dialogOptions['dialogClass'] = "ui-dialog-off-canvas ui-dialog-position-$position";
Chris@14 53 }
Chris@14 54 // If no width option is provided then use the default width to avoid the
Chris@14 55 // dialog staying at the width of the previous instance when opened
Chris@14 56 // more than once, with different widths, on a single page.
Chris@14 57 if (!isset($this->dialogOptions['width'])) {
Chris@14 58 $this->dialogOptions['width'] = static::DEFAULT_DIALOG_WIDTH;
Chris@14 59 }
Chris@14 60 }
Chris@14 61
Chris@14 62 /**
Chris@14 63 * {@inheritdoc}
Chris@14 64 */
Chris@14 65 public function render() {
Chris@14 66 $build = parent::render();
Chris@14 67 $build['effect'] = 'fade';
Chris@14 68 $build['speed'] = 1000;
Chris@14 69 return $build;
Chris@14 70 }
Chris@14 71
Chris@14 72 }