Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Core\Theme;
|
Chris@0
|
4
|
Chris@0
|
5 /**
|
Chris@0
|
6 * Defines a theme and its information needed at runtime.
|
Chris@0
|
7 *
|
Chris@0
|
8 * The theme manager will store the active theme object.
|
Chris@0
|
9 *
|
Chris@0
|
10 * @see \Drupal\Core\Theme\ThemeManager
|
Chris@0
|
11 * @see \Drupal\Core\Theme\ThemeInitialization
|
Chris@0
|
12 */
|
Chris@0
|
13 class ActiveTheme {
|
Chris@0
|
14
|
Chris@0
|
15 /**
|
Chris@0
|
16 * The machine name of the active theme.
|
Chris@0
|
17 *
|
Chris@0
|
18 * @var string
|
Chris@0
|
19 */
|
Chris@0
|
20 protected $name;
|
Chris@0
|
21
|
Chris@0
|
22 /**
|
Chris@0
|
23 * The path to the theme.
|
Chris@0
|
24 *
|
Chris@0
|
25 * @var string
|
Chris@0
|
26 */
|
Chris@0
|
27 protected $path;
|
Chris@0
|
28
|
Chris@0
|
29 /**
|
Chris@0
|
30 * The engine of the theme.
|
Chris@0
|
31 *
|
Chris@0
|
32 * @var string
|
Chris@0
|
33 */
|
Chris@0
|
34 protected $engine;
|
Chris@0
|
35
|
Chris@0
|
36 /**
|
Chris@0
|
37 * The path to the theme engine for root themes.
|
Chris@0
|
38 *
|
Chris@0
|
39 * @var string
|
Chris@0
|
40 */
|
Chris@0
|
41 protected $owner;
|
Chris@0
|
42
|
Chris@0
|
43 /**
|
Chris@0
|
44 * An array of base theme active theme objects keyed by name.
|
Chris@0
|
45 *
|
Chris@0
|
46 * @var static[]
|
Chris@0
|
47 */
|
Chris@0
|
48 protected $baseThemes;
|
Chris@0
|
49
|
Chris@0
|
50 /**
|
Chris@0
|
51 * The extension object.
|
Chris@0
|
52 *
|
Chris@0
|
53 * @var \Drupal\Core\Extension\Extension
|
Chris@0
|
54 */
|
Chris@0
|
55 protected $extension;
|
Chris@0
|
56
|
Chris@0
|
57 /**
|
Chris@0
|
58 * The stylesheets which are set to be removed by the theme.
|
Chris@0
|
59 *
|
Chris@0
|
60 * @var array
|
Chris@0
|
61 */
|
Chris@0
|
62 protected $styleSheetsRemove;
|
Chris@0
|
63
|
Chris@0
|
64 /**
|
Chris@0
|
65 * The libraries provided by the theme.
|
Chris@0
|
66 *
|
Chris@0
|
67 * @var array
|
Chris@0
|
68 */
|
Chris@0
|
69 protected $libraries;
|
Chris@0
|
70
|
Chris@0
|
71 /**
|
Chris@0
|
72 * The regions provided by the theme.
|
Chris@0
|
73 *
|
Chris@0
|
74 * @var array
|
Chris@0
|
75 */
|
Chris@0
|
76 protected $regions;
|
Chris@0
|
77
|
Chris@0
|
78 /**
|
Chris@0
|
79 * The libraries or library assets overridden by the theme.
|
Chris@0
|
80 *
|
Chris@0
|
81 * @var array
|
Chris@0
|
82 */
|
Chris@0
|
83 protected $librariesOverride;
|
Chris@0
|
84
|
Chris@0
|
85 /**
|
Chris@0
|
86 * Constructs an ActiveTheme object.
|
Chris@0
|
87 *
|
Chris@0
|
88 * @param array $values
|
Chris@0
|
89 * The properties of the object, keyed by the names.
|
Chris@0
|
90 */
|
Chris@0
|
91 public function __construct(array $values) {
|
Chris@0
|
92 $values += [
|
Chris@0
|
93 'path' => '',
|
Chris@0
|
94 'engine' => 'twig',
|
Chris@0
|
95 'owner' => 'twig',
|
Chris@0
|
96 'stylesheets_remove' => [],
|
Chris@0
|
97 'libraries' => [],
|
Chris@0
|
98 'extension' => 'html.twig',
|
Chris@0
|
99 'base_themes' => [],
|
Chris@0
|
100 'regions' => [],
|
Chris@0
|
101 'libraries_override' => [],
|
Chris@0
|
102 'libraries_extend' => [],
|
Chris@0
|
103 ];
|
Chris@0
|
104
|
Chris@0
|
105 $this->name = $values['name'];
|
Chris@0
|
106 $this->path = $values['path'];
|
Chris@0
|
107 $this->engine = $values['engine'];
|
Chris@0
|
108 $this->owner = $values['owner'];
|
Chris@0
|
109 $this->styleSheetsRemove = $values['stylesheets_remove'];
|
Chris@0
|
110 $this->libraries = $values['libraries'];
|
Chris@0
|
111 $this->extension = $values['extension'];
|
Chris@0
|
112 $this->baseThemes = $values['base_themes'];
|
Chris@0
|
113 $this->regions = $values['regions'];
|
Chris@0
|
114 $this->librariesOverride = $values['libraries_override'];
|
Chris@0
|
115 $this->librariesExtend = $values['libraries_extend'];
|
Chris@0
|
116 }
|
Chris@0
|
117
|
Chris@0
|
118 /**
|
Chris@0
|
119 * Returns the machine name of the theme.
|
Chris@0
|
120 *
|
Chris@0
|
121 * @return string
|
Chris@0
|
122 */
|
Chris@0
|
123 public function getName() {
|
Chris@0
|
124 return $this->name;
|
Chris@0
|
125 }
|
Chris@0
|
126
|
Chris@0
|
127 /**
|
Chris@0
|
128 * Returns the path to the theme directory.
|
Chris@0
|
129 *
|
Chris@0
|
130 * @return string
|
Chris@0
|
131 */
|
Chris@0
|
132 public function getPath() {
|
Chris@0
|
133 return $this->path;
|
Chris@0
|
134 }
|
Chris@0
|
135
|
Chris@0
|
136 /**
|
Chris@0
|
137 * Returns the theme engine.
|
Chris@0
|
138 *
|
Chris@0
|
139 * @return string
|
Chris@0
|
140 */
|
Chris@0
|
141 public function getEngine() {
|
Chris@0
|
142 return $this->engine;
|
Chris@0
|
143 }
|
Chris@0
|
144
|
Chris@0
|
145 /**
|
Chris@0
|
146 * Returns the path to the theme engine for root themes.
|
Chris@0
|
147 *
|
Chris@0
|
148 * @see \Drupal\Core\Extension\ThemeHandler::rebuildThemeData
|
Chris@0
|
149 *
|
Chris@0
|
150 * @return mixed
|
Chris@0
|
151 */
|
Chris@0
|
152 public function getOwner() {
|
Chris@0
|
153 return $this->owner;
|
Chris@0
|
154 }
|
Chris@0
|
155
|
Chris@0
|
156 /**
|
Chris@0
|
157 * Returns the extension object.
|
Chris@0
|
158 *
|
Chris@0
|
159 * @return \Drupal\Core\Extension\Extension
|
Chris@0
|
160 */
|
Chris@0
|
161 public function getExtension() {
|
Chris@0
|
162 return $this->extension;
|
Chris@0
|
163 }
|
Chris@0
|
164
|
Chris@0
|
165 /**
|
Chris@0
|
166 * Returns the libraries provided by the theme.
|
Chris@0
|
167 *
|
Chris@0
|
168 * @return mixed
|
Chris@0
|
169 */
|
Chris@0
|
170 public function getLibraries() {
|
Chris@0
|
171 return $this->libraries;
|
Chris@0
|
172 }
|
Chris@0
|
173
|
Chris@0
|
174 /**
|
Chris@0
|
175 * Returns the removed stylesheets by the theme.
|
Chris@0
|
176 *
|
Chris@0
|
177 * @return mixed
|
Chris@0
|
178 *
|
Chris@0
|
179 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
|
Chris@0
|
180 *
|
Chris@0
|
181 * @see https://www.drupal.org/node/2497313
|
Chris@0
|
182 */
|
Chris@0
|
183 public function getStyleSheetsRemove() {
|
Chris@0
|
184 return $this->styleSheetsRemove;
|
Chris@0
|
185 }
|
Chris@0
|
186
|
Chris@0
|
187 /**
|
Chris@0
|
188 * Returns an array of base theme active theme objects keyed by name.
|
Chris@0
|
189 *
|
Chris@0
|
190 * The order starts with the base theme of $this and ends with the root of
|
Chris@0
|
191 * the dependency chain.
|
Chris@0
|
192 *
|
Chris@0
|
193 * @return static[]
|
Chris@0
|
194 */
|
Chris@0
|
195 public function getBaseThemes() {
|
Chris@0
|
196 return $this->baseThemes;
|
Chris@0
|
197 }
|
Chris@0
|
198
|
Chris@0
|
199 /**
|
Chris@0
|
200 * The regions used by the theme.
|
Chris@0
|
201 *
|
Chris@0
|
202 * @return string[]
|
Chris@0
|
203 * The list of region machine names supported by the theme.
|
Chris@0
|
204 *
|
Chris@0
|
205 * @see system_region_list()
|
Chris@0
|
206 */
|
Chris@0
|
207 public function getRegions() {
|
Chris@0
|
208 return array_keys($this->regions);
|
Chris@0
|
209 }
|
Chris@0
|
210
|
Chris@0
|
211 /**
|
Chris@0
|
212 * Returns the libraries or library assets overridden by the active theme.
|
Chris@0
|
213 *
|
Chris@0
|
214 * @return array
|
Chris@0
|
215 * The list of libraries overrides.
|
Chris@0
|
216 */
|
Chris@0
|
217 public function getLibrariesOverride() {
|
Chris@0
|
218 return $this->librariesOverride;
|
Chris@0
|
219 }
|
Chris@0
|
220
|
Chris@0
|
221 /**
|
Chris@0
|
222 * Returns the libraries extended by the active theme.
|
Chris@0
|
223 *
|
Chris@0
|
224 * @return array
|
Chris@0
|
225 * The list of libraries-extend definitions.
|
Chris@0
|
226 */
|
Chris@0
|
227 public function getLibrariesExtend() {
|
Chris@0
|
228 return $this->librariesExtend;
|
Chris@0
|
229 }
|
Chris@0
|
230
|
Chris@0
|
231 }
|