Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Core\Config;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Component\Utility\NestedArray;
|
Chris@0
|
6 use Drupal\Core\Language\LanguageInterface;
|
Chris@0
|
7 use Symfony\Component\EventDispatcher\Event;
|
Chris@0
|
8
|
Chris@0
|
9 /**
|
Chris@0
|
10 * Event object to allow configuration to be overridden by modules.
|
Chris@0
|
11 */
|
Chris@0
|
12 class ConfigModuleOverridesEvent extends Event {
|
Chris@0
|
13
|
Chris@0
|
14 /**
|
Chris@0
|
15 * Configuration names.
|
Chris@0
|
16 *
|
Chris@0
|
17 * @var array
|
Chris@0
|
18 */
|
Chris@0
|
19 protected $names;
|
Chris@0
|
20
|
Chris@0
|
21 /**
|
Chris@0
|
22 * Configuration overrides.
|
Chris@0
|
23 *
|
Chris@0
|
24 * @var array
|
Chris@0
|
25 */
|
Chris@0
|
26 protected $overrides;
|
Chris@0
|
27
|
Chris@0
|
28 /**
|
Chris@0
|
29 * The Language object used to override configuration data.
|
Chris@0
|
30 *
|
Chris@0
|
31 * @var \Drupal\Core\Language\LanguageInterface
|
Chris@0
|
32 */
|
Chris@0
|
33 protected $language;
|
Chris@0
|
34
|
Chris@0
|
35 /**
|
Chris@0
|
36 * Constructs a configuration overrides event object.
|
Chris@0
|
37 *
|
Chris@0
|
38 * @param array $names
|
Chris@0
|
39 * A list of configuration names.
|
Chris@0
|
40 * @param \Drupal\Core\Language\LanguageInterface $language
|
Chris@0
|
41 * (optional) The language for this configuration.
|
Chris@0
|
42 */
|
Chris@0
|
43 public function __construct(array $names, LanguageInterface $language = NULL) {
|
Chris@0
|
44 $this->names = $names;
|
Chris@0
|
45 $this->language = $language;
|
Chris@0
|
46 $this->overrides = [];
|
Chris@0
|
47 }
|
Chris@0
|
48
|
Chris@0
|
49 /**
|
Chris@0
|
50 * Gets configuration names.
|
Chris@0
|
51 *
|
Chris@0
|
52 * @return array
|
Chris@0
|
53 * The list of configuration names that can be overridden.
|
Chris@0
|
54 */
|
Chris@0
|
55 public function getNames() {
|
Chris@0
|
56 return $this->names;
|
Chris@0
|
57 }
|
Chris@0
|
58
|
Chris@0
|
59 /**
|
Chris@0
|
60 * Gets configuration language.
|
Chris@0
|
61 *
|
Chris@0
|
62 * @return \Drupal\Core\Language\LanguageInterface
|
Chris@0
|
63 * The configuration language object.
|
Chris@0
|
64 */
|
Chris@0
|
65 public function getLanguage() {
|
Chris@0
|
66 return $this->language;
|
Chris@0
|
67 }
|
Chris@0
|
68
|
Chris@0
|
69 /**
|
Chris@0
|
70 * Get configuration overrides.
|
Chris@0
|
71 *
|
Chris@0
|
72 * @return array
|
Chris@0
|
73 * The array of configuration overrides.
|
Chris@0
|
74 */
|
Chris@0
|
75 public function getOverrides() {
|
Chris@0
|
76 return $this->overrides;
|
Chris@0
|
77 }
|
Chris@0
|
78
|
Chris@0
|
79 /**
|
Chris@0
|
80 * Sets a configuration override for the given name.
|
Chris@0
|
81 *
|
Chris@0
|
82 * @param string $name
|
Chris@0
|
83 * The configuration object name to override.
|
Chris@0
|
84 * @param array $values
|
Chris@0
|
85 * The values in the configuration object to override.
|
Chris@0
|
86 *
|
Chris@0
|
87 * @return $this
|
Chris@0
|
88 */
|
Chris@0
|
89 public function setOverride($name, array $values) {
|
Chris@0
|
90 if (in_array($name, $this->names)) {
|
Chris@0
|
91 if (isset($this->overrides[$name])) {
|
Chris@0
|
92 // Existing overrides take precedence since these will have been added
|
Chris@0
|
93 // by events with a higher priority.
|
Chris@0
|
94 $this->overrides[$name] = NestedArray::mergeDeepArray([$values, $this->overrides[$name]], TRUE);
|
Chris@0
|
95 }
|
Chris@0
|
96 else {
|
Chris@0
|
97 $this->overrides[$name] = $values;
|
Chris@0
|
98 }
|
Chris@0
|
99 }
|
Chris@0
|
100 return $this;
|
Chris@0
|
101 }
|
Chris@0
|
102
|
Chris@0
|
103 }
|