ThemeHandlerInterface.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. namespace Drupal\Core\Extension;
  3. /**
  4. * Manages the list of available themes.
  5. */
  6. interface ThemeHandlerInterface {
  7. /**
  8. * Installs a given list of themes.
  9. *
  10. * @param array $theme_list
  11. * An array of theme names.
  12. * @param bool $install_dependencies
  13. * (optional) If TRUE, dependencies will automatically be installed in the
  14. * correct order. This incurs a significant performance cost, so use FALSE
  15. * if you know $theme_list is already complete and in the correct order.
  16. *
  17. * @return bool
  18. * Whether any of the given themes have been installed.
  19. *
  20. * @throws \Drupal\Core\Extension\ExtensionNameLengthException
  21. * Thrown when the theme name is to long.
  22. *
  23. * @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0.
  24. * Use the theme_installer service instead.
  25. *
  26. * @see https://www.drupal.org/node/3017233
  27. * @see \Drupal\Core\Extension\ThemeInstallerInterface::install()
  28. */
  29. public function install(array $theme_list, $install_dependencies = TRUE);
  30. /**
  31. * Uninstalls a given list of themes.
  32. *
  33. * Uninstalling a theme removes all related configuration (like blocks) and
  34. * invokes the 'themes_uninstalled' hook.
  35. *
  36. * @param array $theme_list
  37. * The themes to uninstall.
  38. *
  39. * @throws \Drupal\Core\Extension\Exception\UninstalledExtensionException
  40. * Thrown when you try to uninstall a theme that wasn't installed.
  41. *
  42. * @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0.
  43. * Use the theme_installer service instead.
  44. *
  45. * @see https://www.drupal.org/node/3017233
  46. * @see hook_themes_uninstalled()
  47. * @see \Drupal\Core\Extension\ThemeInstallerInterface::uninstall()
  48. */
  49. public function uninstall(array $theme_list);
  50. /**
  51. * Returns a list of currently installed themes.
  52. *
  53. * @return \Drupal\Core\Extension\Extension[]
  54. * An associative array of the currently installed themes. The keys are the
  55. * themes' machine names and the values are Extension objects having the
  56. * following properties:
  57. * - filename: The filepath and name of the .info.yml file.
  58. * - name: The machine name of the theme.
  59. * - status: 1 for installed, 0 for uninstalled themes.
  60. * - info: The contents of the .info.yml file.
  61. * - stylesheets: A two dimensional array, using the first key for the
  62. * media attribute (e.g. 'all'), the second for the name of the file
  63. * (e.g. style.css). The value is a complete filepath (e.g.
  64. * themes/bartik/style.css). Not set if no stylesheets are defined in the
  65. * .info.yml file.
  66. * - scripts: An associative array of JavaScripts, using the filename as key
  67. * and the complete filepath as value. Not set if no scripts are defined
  68. * in the .info.yml file.
  69. * - prefix: The base theme engine prefix.
  70. * - engine: The machine name of the theme engine.
  71. * - base_theme: If this is a sub-theme, the machine name of the base theme
  72. * defined in the .info.yml file. Otherwise, the element is not set.
  73. * - base_themes: If this is a sub-theme, an associative array of the
  74. * base-theme ancestors of this theme, starting with this theme's base
  75. * theme, then the base theme's own base theme, etc. Each entry has an
  76. * array key equal to the theme's machine name, and a value equal to the
  77. * human-readable theme name; if a theme with matching machine name does
  78. * not exist in the system, the value will instead be NULL (and since the
  79. * system would not know whether that theme itself has a base theme, that
  80. * will end the array of base themes). This is not set if the theme is not
  81. * a sub-theme.
  82. * - sub_themes: An associative array of themes on the system that are
  83. * either direct sub-themes (that is, they declare this theme to be
  84. * their base theme), direct sub-themes of sub-themes, etc. The keys are
  85. * the themes' machine names, and the values are the themes'
  86. * human-readable names. This element is not set if there are no themes on
  87. * the system that declare this theme as their base theme.
  88. */
  89. public function listInfo();
  90. /**
  91. * Adds a theme extension to the internal listing.
  92. *
  93. * @param \Drupal\Core\Extension\Extension $theme
  94. * The theme extension.
  95. */
  96. public function addTheme(Extension $theme);
  97. /**
  98. * Refreshes the theme info data of currently installed themes.
  99. *
  100. * Modules can alter theme info, so this is typically called after a module
  101. * has been installed or uninstalled.
  102. */
  103. public function refreshInfo();
  104. /**
  105. * Resets the internal state of the theme handler.
  106. */
  107. public function reset();
  108. /**
  109. * Scans and collects theme extension data and their engines.
  110. *
  111. * @return \Drupal\Core\Extension\Extension[]
  112. * An associative array of theme extensions.
  113. */
  114. public function rebuildThemeData();
  115. /**
  116. * Finds all the base themes for the specified theme.
  117. *
  118. * Themes can inherit templates and function implementations from earlier
  119. * themes.
  120. *
  121. * @param \Drupal\Core\Extension\Extension[] $themes
  122. * An array of available themes.
  123. * @param string $theme
  124. * The name of the theme whose base we are looking for.
  125. *
  126. * @return array
  127. * Returns an array of all of the theme's ancestors; the first element's
  128. * value will be NULL if an error occurred.
  129. */
  130. public function getBaseThemes(array $themes, $theme);
  131. /**
  132. * Gets the human readable name of a given theme.
  133. *
  134. * @param string $theme
  135. * The machine name of the theme which title should be shown.
  136. *
  137. * @return string
  138. * Returns the human readable name of the theme.
  139. *
  140. * @throws \Drupal\Core\Extension\Exception\UnknownExtensionException
  141. * When the specified theme does not exist.
  142. */
  143. public function getName($theme);
  144. /**
  145. * Returns the default theme.
  146. *
  147. * @return string
  148. * The default theme.
  149. */
  150. public function getDefault();
  151. /**
  152. * Sets a new default theme.
  153. *
  154. * @param string $theme
  155. * The new default theme.
  156. *
  157. * @return $this
  158. *
  159. * @deprecated in drupal:8.2.0 and is removed from drupal:9.0.0. Use the
  160. * configuration system to edit the system.theme config directly.
  161. *
  162. * @see https://www.drupal.org/node/3082630
  163. */
  164. public function setDefault($theme);
  165. /**
  166. * Returns an array of directories for all installed themes.
  167. *
  168. * Useful for tasks such as finding a file that exists in all theme
  169. * directories.
  170. *
  171. * @return array
  172. */
  173. public function getThemeDirectories();
  174. /**
  175. * Determines whether a given theme is installed.
  176. *
  177. * @param string $theme
  178. * The name of the theme (without the .theme extension).
  179. *
  180. * @return bool
  181. * TRUE if the theme is installed.
  182. */
  183. public function themeExists($theme);
  184. /**
  185. * Returns a theme extension object from the currently active theme list.
  186. *
  187. * @param string $name
  188. * The name of the theme to return.
  189. *
  190. * @return \Drupal\Core\Extension\Extension
  191. * An extension object.
  192. *
  193. * @throws \Drupal\Core\Extension\Extension\UnknownExtensionException
  194. * Thrown when the requested theme does not exist.
  195. */
  196. public function getTheme($name);
  197. /**
  198. * Determines if a theme should be shown in the user interface.
  199. *
  200. * To be shown in the UI the theme has to be installed. If the theme is hidden
  201. * it will not be shown unless it is the default or admin theme.
  202. *
  203. * @param string $name
  204. * The name of the theme to check.
  205. *
  206. * @return bool
  207. * TRUE if the theme should be shown in the UI, FALSE if not.
  208. */
  209. public function hasUi($name);
  210. }