class OpenDialogCommand
Same name in other branches
- 9 core/lib/Drupal/Core/Ajax/OpenDialogCommand.php \Drupal\Core\Ajax\OpenDialogCommand
- 8.9.x core/lib/Drupal/Core/Ajax/OpenDialogCommand.php \Drupal\Core\Ajax\OpenDialogCommand
- 10 core/lib/Drupal/Core/Ajax/OpenDialogCommand.php \Drupal\Core\Ajax\OpenDialogCommand
Defines an AJAX command to open certain content in a dialog.
Hierarchy
- class \Drupal\Core\Ajax\OpenDialogCommand implements \Drupal\Core\Ajax\CommandInterface, \Drupal\Core\Ajax\CommandWithAttachedAssetsInterface uses \Drupal\Core\Ajax\CommandWithAttachedAssetsTrait
Expanded class hierarchy of OpenDialogCommand
Related topics
3 files declare their use of OpenDialogCommand
- AjaxCommandsTest.php in core/
tests/ Drupal/ Tests/ Core/ Ajax/ AjaxCommandsTest.php - AjaxTestDialogForm.php in core/
modules/ system/ tests/ modules/ ajax_test/ src/ Form/ AjaxTestDialogForm.php - DialogRenderer.php in core/
lib/ Drupal/ Core/ Render/ MainContent/ DialogRenderer.php
File
-
core/
lib/ Drupal/ Core/ Ajax/ OpenDialogCommand.php, line 12
Namespace
Drupal\Core\AjaxView source
class OpenDialogCommand implements CommandInterface, CommandWithAttachedAssetsInterface {
use CommandWithAttachedAssetsTrait;
/**
* The selector of the dialog.
*
* @var string
*/
protected $selector;
/**
* The title of the dialog.
*
* @var string
*/
protected $title;
/**
* The content for the dialog.
*
* Either a render array or an HTML string.
*
* @var string|array
*/
protected $content;
/**
* Stores dialog-specific options passed directly to jQuery UI dialogs.
*
* Any jQuery UI option can be used.
*
* @var array
*
* @see http://api.jqueryui.com/dialog.
*/
protected $dialogOptions;
/**
* Custom settings passed to Drupal behaviors on the content of the dialog.
*
* @var array
*/
protected $settings;
/**
* Constructs an OpenDialogCommand object.
*
* @param string $selector
* The selector of the dialog.
* @param string|\Stringable|null $title
* The title of the dialog.
* @param string|array $content
* The content that will be placed in the dialog, either a render array
* or an HTML string.
* @param array $dialog_options
* (optional) Options to be passed to the dialog implementation. Any
* jQuery UI option can be used. See http://api.jqueryui.com/dialog.
* @param array|null $settings
* (optional) Custom settings that will be passed to the Drupal behaviors
* on the content of the dialog. If left empty, the settings will be
* populated automatically from the current request.
*/
public function __construct($selector, string|\Stringable|null $title, $content, array $dialog_options = [], $settings = NULL) {
$title = PlainTextOutput::renderFromHtml($title);
$dialog_options += [
'title' => $title,
];
if (isset($dialog_options['dialogClass'])) {
@trigger_error('Passing $dialog_options[\'dialogClass\'] to OpenDialogCommand::__construct() is deprecated in drupal:10.3.0 and will be removed in drupal:12.0.0. Use $dialog_options[\'classes\'] instead. See https://www.drupal.org/node/3440844', E_USER_DEPRECATED);
$dialog_options['classes']['ui-dialog'] = $dialog_options['dialogClass'];
unset($dialog_options['dialogClass']);
}
$this->selector = $selector;
$this->content = $content;
$this->dialogOptions = $dialog_options;
$this->settings = $settings;
}
/**
* Returns the dialog options.
*
* @return array
*/
public function getDialogOptions() {
return $this->dialogOptions;
}
/**
* Sets the dialog options array.
*
* @param array $dialog_options
* Options to be passed to the dialog implementation. Any jQuery UI option
* can be used. See http://api.jqueryui.com/dialog.
*/
public function setDialogOptions($dialog_options) {
$this->dialogOptions = $dialog_options;
}
/**
* Sets a single dialog option value.
*
* @param string $key
* Key of the dialog option. Any jQuery UI option can be used.
* See http://api.jqueryui.com/dialog.
* @param mixed $value
* Option to be passed to the dialog implementation.
*/
public function setDialogOption($key, $value) {
$this->dialogOptions[$key] = $value;
}
/**
* Sets the dialog title (an alias of setDialogOptions).
*
* @param string $title
* The new title of the dialog.
*/
public function setDialogTitle($title) {
$this->setDialogOption('title', $title);
}
/**
* Implements \Drupal\Core\Ajax\CommandInterface:render().
*/
public function render() {
// For consistency ensure the modal option is set to TRUE or FALSE.
$this->dialogOptions['modal'] = isset($this->dialogOptions['modal']) && $this->dialogOptions['modal'];
return [
'command' => 'openDialog',
'selector' => $this->selector,
'settings' => $this->settings,
'data' => $this->getRenderedContent(),
'dialogOptions' => $this->dialogOptions,
];
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
CommandWithAttachedAssetsTrait::$attachedAssets | protected | property | The attached assets for this Ajax command. | ||
CommandWithAttachedAssetsTrait::getAttachedAssets | public | function | Gets the attached assets. | ||
CommandWithAttachedAssetsTrait::getRenderedContent | protected | function | Processes the content for output. | ||
OpenDialogCommand::$content | protected | property | The content for the dialog. | ||
OpenDialogCommand::$dialogOptions | protected | property | Stores dialog-specific options passed directly to jQuery UI dialogs. | ||
OpenDialogCommand::$selector | protected | property | The selector of the dialog. | ||
OpenDialogCommand::$settings | protected | property | Custom settings passed to Drupal behaviors on the content of the dialog. | ||
OpenDialogCommand::$title | protected | property | The title of the dialog. | ||
OpenDialogCommand::getDialogOptions | public | function | Returns the dialog options. | ||
OpenDialogCommand::render | public | function | Implements \Drupal\Core\Ajax\CommandInterface:render(). | Overrides CommandInterface::render | 1 |
OpenDialogCommand::setDialogOption | public | function | Sets a single dialog option value. | ||
OpenDialogCommand::setDialogOptions | public | function | Sets the dialog options array. | ||
OpenDialogCommand::setDialogTitle | public | function | Sets the dialog title (an alias of setDialogOptions). | ||
OpenDialogCommand::__construct | public | function | Constructs an OpenDialogCommand object. | 2 |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.