annotate core/lib/Drupal/Core/Theme/ActiveTheme.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
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@17 23 * The path to the logo.
Chris@17 24 *
Chris@17 25 * @var string
Chris@17 26 */
Chris@17 27 protected $logo;
Chris@17 28
Chris@17 29 /**
Chris@0 30 * The path to the theme.
Chris@0 31 *
Chris@0 32 * @var string
Chris@0 33 */
Chris@0 34 protected $path;
Chris@0 35
Chris@0 36 /**
Chris@0 37 * The engine of the theme.
Chris@0 38 *
Chris@0 39 * @var string
Chris@0 40 */
Chris@0 41 protected $engine;
Chris@0 42
Chris@0 43 /**
Chris@0 44 * The path to the theme engine for root themes.
Chris@0 45 *
Chris@0 46 * @var string
Chris@0 47 */
Chris@0 48 protected $owner;
Chris@0 49
Chris@0 50 /**
Chris@0 51 * An array of base theme active theme objects keyed by name.
Chris@0 52 *
Chris@0 53 * @var static[]
Chris@18 54 *
Chris@18 55 * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9. Use
Chris@18 56 * $this->baseThemeExtensions instead.
Chris@18 57 *
Chris@18 58 * @see https://www.drupal.org/node/3019948
Chris@0 59 */
Chris@0 60 protected $baseThemes;
Chris@0 61
Chris@0 62 /**
Chris@18 63 * An array of base theme extension objects keyed by name.
Chris@18 64 *
Chris@18 65 * @var \Drupal\Core\Extension\Extension[]
Chris@18 66 */
Chris@18 67 protected $baseThemeExtensions = [];
Chris@18 68
Chris@18 69 /**
Chris@0 70 * The extension object.
Chris@0 71 *
Chris@0 72 * @var \Drupal\Core\Extension\Extension
Chris@0 73 */
Chris@0 74 protected $extension;
Chris@0 75
Chris@0 76 /**
Chris@0 77 * The stylesheets which are set to be removed by the theme.
Chris@0 78 *
Chris@0 79 * @var array
Chris@0 80 */
Chris@0 81 protected $styleSheetsRemove;
Chris@0 82
Chris@0 83 /**
Chris@0 84 * The libraries provided by the theme.
Chris@0 85 *
Chris@0 86 * @var array
Chris@0 87 */
Chris@0 88 protected $libraries;
Chris@0 89
Chris@0 90 /**
Chris@0 91 * The regions provided by the theme.
Chris@0 92 *
Chris@0 93 * @var array
Chris@0 94 */
Chris@0 95 protected $regions;
Chris@0 96
Chris@0 97 /**
Chris@0 98 * The libraries or library assets overridden by the theme.
Chris@0 99 *
Chris@0 100 * @var array
Chris@0 101 */
Chris@0 102 protected $librariesOverride;
Chris@0 103
Chris@0 104 /**
Chris@17 105 * The list of libraries-extend definitions.
Chris@17 106 *
Chris@17 107 * @var array
Chris@17 108 */
Chris@17 109 protected $librariesExtend;
Chris@17 110
Chris@17 111 /**
Chris@0 112 * Constructs an ActiveTheme object.
Chris@0 113 *
Chris@0 114 * @param array $values
Chris@0 115 * The properties of the object, keyed by the names.
Chris@0 116 */
Chris@0 117 public function __construct(array $values) {
Chris@0 118 $values += [
Chris@0 119 'path' => '',
Chris@0 120 'engine' => 'twig',
Chris@0 121 'owner' => 'twig',
Chris@17 122 'logo' => '',
Chris@0 123 'stylesheets_remove' => [],
Chris@0 124 'libraries' => [],
Chris@0 125 'extension' => 'html.twig',
Chris@18 126 'base_theme_extensions' => [],
Chris@0 127 'regions' => [],
Chris@0 128 'libraries_override' => [],
Chris@0 129 'libraries_extend' => [],
Chris@0 130 ];
Chris@0 131
Chris@0 132 $this->name = $values['name'];
Chris@17 133 $this->logo = $values['logo'];
Chris@0 134 $this->path = $values['path'];
Chris@0 135 $this->engine = $values['engine'];
Chris@0 136 $this->owner = $values['owner'];
Chris@0 137 $this->styleSheetsRemove = $values['stylesheets_remove'];
Chris@0 138 $this->libraries = $values['libraries'];
Chris@0 139 $this->extension = $values['extension'];
Chris@18 140 $this->baseThemeExtensions = $values['base_theme_extensions'];
Chris@18 141 if (!empty($values['base_themes']) && empty($this->baseThemeExtensions)) {
Chris@18 142 @trigger_error("The 'base_themes' key is deprecated in Drupal 8.7.0 and support for it will be removed in Drupal 9.0.0. Use 'base_theme_extensions' instead. See https://www.drupal.org/node/3019948", E_USER_DEPRECATED);
Chris@18 143 foreach ($values['base_themes'] as $base_theme) {
Chris@18 144 $this->baseThemeExtensions[$base_theme->getName()] = $base_theme->getExtension();
Chris@18 145 }
Chris@18 146 }
Chris@18 147
Chris@0 148 $this->regions = $values['regions'];
Chris@0 149 $this->librariesOverride = $values['libraries_override'];
Chris@0 150 $this->librariesExtend = $values['libraries_extend'];
Chris@0 151 }
Chris@0 152
Chris@0 153 /**
Chris@0 154 * Returns the machine name of the theme.
Chris@0 155 *
Chris@0 156 * @return string
Chris@0 157 */
Chris@0 158 public function getName() {
Chris@0 159 return $this->name;
Chris@0 160 }
Chris@0 161
Chris@0 162 /**
Chris@0 163 * Returns the path to the theme directory.
Chris@0 164 *
Chris@0 165 * @return string
Chris@0 166 */
Chris@0 167 public function getPath() {
Chris@0 168 return $this->path;
Chris@0 169 }
Chris@0 170
Chris@0 171 /**
Chris@0 172 * Returns the theme engine.
Chris@0 173 *
Chris@0 174 * @return string
Chris@0 175 */
Chris@0 176 public function getEngine() {
Chris@0 177 return $this->engine;
Chris@0 178 }
Chris@0 179
Chris@0 180 /**
Chris@0 181 * Returns the path to the theme engine for root themes.
Chris@0 182 *
Chris@18 183 * @see \Drupal\Core\Extension\ThemeExtensionList::doList()
Chris@0 184 *
Chris@0 185 * @return mixed
Chris@0 186 */
Chris@0 187 public function getOwner() {
Chris@0 188 return $this->owner;
Chris@0 189 }
Chris@0 190
Chris@0 191 /**
Chris@0 192 * Returns the extension object.
Chris@0 193 *
Chris@0 194 * @return \Drupal\Core\Extension\Extension
Chris@0 195 */
Chris@0 196 public function getExtension() {
Chris@0 197 return $this->extension;
Chris@0 198 }
Chris@0 199
Chris@0 200 /**
Chris@0 201 * Returns the libraries provided by the theme.
Chris@0 202 *
Chris@0 203 * @return mixed
Chris@0 204 */
Chris@0 205 public function getLibraries() {
Chris@0 206 return $this->libraries;
Chris@0 207 }
Chris@0 208
Chris@0 209 /**
Chris@0 210 * Returns the removed stylesheets by the theme.
Chris@0 211 *
Chris@0 212 * @return mixed
Chris@0 213 *
Chris@0 214 * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
Chris@0 215 *
Chris@0 216 * @see https://www.drupal.org/node/2497313
Chris@0 217 */
Chris@0 218 public function getStyleSheetsRemove() {
Chris@0 219 return $this->styleSheetsRemove;
Chris@0 220 }
Chris@0 221
Chris@0 222 /**
Chris@0 223 * Returns an array of base theme active theme objects keyed by name.
Chris@0 224 *
Chris@0 225 * The order starts with the base theme of $this and ends with the root of
Chris@0 226 * the dependency chain.
Chris@0 227 *
Chris@0 228 * @return static[]
Chris@18 229 *
Chris@18 230 * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use
Chris@18 231 * \Drupal\Core\Theme\ActiveTheme::getBaseThemeExtensions() instead.
Chris@18 232 *
Chris@18 233 * @see https://www.drupal.org/node/3019948
Chris@0 234 */
Chris@0 235 public function getBaseThemes() {
Chris@18 236 @trigger_error('\Drupal\Core\Theme\ActiveTheme::getBaseThemes() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Theme\ActiveTheme::getBaseThemeExtensions() instead. See https://www.drupal.org/node/3019948', E_USER_DEPRECATED);
Chris@18 237 /** @var \Drupal\Core\Theme\ThemeInitialization $theme_initialisation */
Chris@18 238 $theme_initialisation = \Drupal::service('theme.initialization');
Chris@18 239 $base_themes = array_combine(array_keys($this->baseThemeExtensions), array_keys($this->baseThemeExtensions));
Chris@18 240 return array_map([$theme_initialisation, 'getActiveThemeByName'], $base_themes);
Chris@18 241 }
Chris@18 242
Chris@18 243 /**
Chris@18 244 * Returns an array of base theme extension objects keyed by name.
Chris@18 245 *
Chris@18 246 * The order starts with the base theme of $this and ends with the root of
Chris@18 247 * the dependency chain.
Chris@18 248 *
Chris@18 249 * @return \Drupal\Core\Extension\Extension[]
Chris@18 250 */
Chris@18 251 public function getBaseThemeExtensions() {
Chris@18 252 return $this->baseThemeExtensions;
Chris@0 253 }
Chris@0 254
Chris@0 255 /**
Chris@17 256 * Returns the logo provided by the theme.
Chris@17 257 *
Chris@17 258 * @return string
Chris@17 259 * The logo path.
Chris@17 260 */
Chris@17 261 public function getLogo() {
Chris@17 262 return $this->logo;
Chris@17 263 }
Chris@17 264
Chris@17 265 /**
Chris@0 266 * The regions used by the theme.
Chris@0 267 *
Chris@0 268 * @return string[]
Chris@0 269 * The list of region machine names supported by the theme.
Chris@0 270 *
Chris@0 271 * @see system_region_list()
Chris@0 272 */
Chris@0 273 public function getRegions() {
Chris@0 274 return array_keys($this->regions);
Chris@0 275 }
Chris@0 276
Chris@0 277 /**
Chris@0 278 * Returns the libraries or library assets overridden by the active theme.
Chris@0 279 *
Chris@0 280 * @return array
Chris@0 281 * The list of libraries overrides.
Chris@0 282 */
Chris@0 283 public function getLibrariesOverride() {
Chris@0 284 return $this->librariesOverride;
Chris@0 285 }
Chris@0 286
Chris@0 287 /**
Chris@0 288 * Returns the libraries extended by the active theme.
Chris@0 289 *
Chris@0 290 * @return array
Chris@0 291 * The list of libraries-extend definitions.
Chris@0 292 */
Chris@0 293 public function getLibrariesExtend() {
Chris@0 294 return $this->librariesExtend;
Chris@0 295 }
Chris@0 296
Chris@0 297 }