class SettingsCommand
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Ajax/SettingsCommand.php \Drupal\Core\Ajax\SettingsCommand
- 10 core/lib/Drupal/Core/Ajax/SettingsCommand.php \Drupal\Core\Ajax\SettingsCommand
- 9 core/lib/Drupal/Core/Ajax/SettingsCommand.php \Drupal\Core\Ajax\SettingsCommand
- 8.9.x core/lib/Drupal/Core/Ajax/SettingsCommand.php \Drupal\Core\Ajax\SettingsCommand
AJAX command for adjusting Drupal's JavaScript settings.
The 'settings' command instructs the client either to use the given array as the settings for ajax-loaded content or to extend drupalSettings with the given array, depending on the value of the $merge parameter.
This command is implemented by Drupal.AjaxCommands.prototype.settings() defined in misc/ajax.js.
Hierarchy
- class \Drupal\Core\Ajax\SettingsCommand implements \Drupal\Core\Ajax\CommandInterface
Expanded class hierarchy of SettingsCommand
Related topics
3 files declare their use of SettingsCommand
- AjaxCommandsTest.php in core/
tests/ Drupal/ Tests/ Core/ Ajax/ AjaxCommandsTest.php - Callbacks.php in core/
modules/ system/ tests/ modules/ ajax_forms_test/ src/ Callbacks.php - FrameworkTest.php in core/
modules/ system/ tests/ src/ Functional/ Ajax/ FrameworkTest.php
File
-
core/
lib/ Drupal/ Core/ Ajax/ SettingsCommand.php, line 19
Namespace
Drupal\Core\AjaxView source
class SettingsCommand implements CommandInterface {
/**
* Constructs a SettingsCommand object.
*
* @param array $settings
* An array of key/value pairs of JavaScript settings.
* @param bool $merge
* Whether the settings should be merged into the global drupalSettings.
*/
public function __construct(protected array $settings, protected $merge = FALSE) {
}
/**
* Implements Drupal\Core\Ajax\CommandInterface:render().
*/
public function render() {
if (isset($this->settings['ajax_page_state']['libraries'])) {
$this->settings['ajax_page_state']['libraries'] = UrlHelper::compressQueryParameter($this->settings['ajax_page_state']['libraries']);
}
return [
'command' => 'settings',
'settings' => $this->settings,
'merge' => $this->merge,
];
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
|---|---|---|---|---|
| SettingsCommand::render | public | function | Implements Drupal\Core\Ajax\CommandInterface:render(). | Overrides CommandInterface::render |
| SettingsCommand::__construct | public | function | Constructs a SettingsCommand object. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.