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