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

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Core\Ajax;
Chris@0 4
Chris@0 5 /**
Chris@0 6 * AJAX command for adjusting Drupal's JavaScript settings.
Chris@0 7 *
Chris@0 8 * The 'settings' command instructs the client either to use the given array as
Chris@0 9 * the settings for ajax-loaded content or to extend drupalSettings with the
Chris@0 10 * given array, depending on the value of the $merge parameter.
Chris@0 11 *
Chris@0 12 * This command is implemented by Drupal.AjaxCommands.prototype.settings()
Chris@0 13 * defined in misc/ajax.js.
Chris@0 14 *
Chris@0 15 * @ingroup ajax
Chris@0 16 */
Chris@0 17 class SettingsCommand implements CommandInterface {
Chris@0 18
Chris@0 19 /**
Chris@0 20 * An array of key/value pairs of JavaScript settings.
Chris@0 21 *
Chris@0 22 * This will be used for all commands after this if they do not include their
Chris@0 23 * own settings array.
Chris@0 24 *
Chris@0 25 * @var array
Chris@0 26 */
Chris@0 27 protected $settings;
Chris@0 28
Chris@0 29 /**
Chris@0 30 * Whether the settings should be merged into the global drupalSettings.
Chris@0 31 *
Chris@0 32 * By default (FALSE), the settings that are passed to Drupal.attachBehaviors
Chris@0 33 * will not include the global drupalSettings.
Chris@0 34 *
Chris@0 35 * @var bool
Chris@0 36 */
Chris@0 37 protected $merge;
Chris@0 38
Chris@0 39 /**
Chris@0 40 * Constructs a SettingsCommand object.
Chris@0 41 *
Chris@0 42 * @param array $settings
Chris@0 43 * An array of key/value pairs of JavaScript settings.
Chris@0 44 * @param bool $merge
Chris@0 45 * Whether the settings should be merged into the global drupalSettings.
Chris@0 46 */
Chris@0 47 public function __construct(array $settings, $merge = FALSE) {
Chris@0 48 $this->settings = $settings;
Chris@0 49 $this->merge = $merge;
Chris@0 50 }
Chris@0 51
Chris@0 52 /**
Chris@0 53 * Implements Drupal\Core\Ajax\CommandInterface:render().
Chris@0 54 */
Chris@0 55 public function render() {
Chris@0 56
Chris@0 57 return [
Chris@0 58 'command' => 'settings',
Chris@0 59 'settings' => $this->settings,
Chris@0 60 'merge' => $this->merge,
Chris@0 61 ];
Chris@0 62 }
Chris@0 63
Chris@0 64 }