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