ActiveTheme.php 4.5 KB

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