3 namespace Drupal\Core\Extension;
6 * Manages the list of available themes.
8 interface ThemeHandlerInterface {
11 * Installs a given list of themes.
13 * @param array $theme_list
14 * An array of theme names.
15 * @param bool $install_dependencies
16 * (optional) If TRUE, dependencies will automatically be installed in the
17 * correct order. This incurs a significant performance cost, so use FALSE
18 * if you know $theme_list is already complete and in the correct order.
21 * Whether any of the given themes have been installed.
23 * @throws \Drupal\Core\Extension\ExtensionNameLengthException
24 * Thrown when the theme name is to long.
26 * @deprecated in Drupal 8.0.x-dev and will be removed before Drupal 9.0.0.
27 * Use the theme_installer service instead.
29 * @see \Drupal\Core\Extension\ThemeInstallerInterface::install
31 public function install(array $theme_list, $install_dependencies = TRUE);
34 * Uninstalls a given list of themes.
36 * Uninstalling a theme removes all related configuration (like blocks) and
37 * invokes the 'themes_uninstalled' hook.
39 * @param array $theme_list
40 * The themes to uninstall.
42 * @throws \Drupal\Core\Extension\Exception\UninstalledExtensionException
43 * Thrown when you try to uninstall a theme that wasn't installed.
45 * @see hook_themes_uninstalled()
47 * @deprecated in Drupal 8.0.x-dev and will be removed before Drupal 9.0.0.
48 * Use the theme_installer service instead.
50 * @see \Drupal\Core\Extension\ThemeInstallerInterface::uninstall
52 public function uninstall(array $theme_list);
55 * Returns a list of currently installed themes.
57 * @return \Drupal\Core\Extension\Extension[]
58 * An associative array of the currently installed themes. The keys are the
59 * themes' machine names and the values are objects having the following
61 * - filename: The filepath and name of the .info.yml file.
62 * - name: The machine name of the theme.
63 * - status: 1 for installed, 0 for uninstalled themes.
64 * - info: The contents of the .info.yml file.
65 * - stylesheets: A two dimensional array, using the first key for the
66 * media attribute (e.g. 'all'), the second for the name of the file
67 * (e.g. style.css). The value is a complete filepath (e.g.
68 * themes/bartik/style.css). Not set if no stylesheets are defined in the
70 * - scripts: An associative array of JavaScripts, using the filename as key
71 * and the complete filepath as value. Not set if no scripts are defined
72 * in the .info.yml file.
73 * - prefix: The base theme engine prefix.
74 * - engine: The machine name of the theme engine.
75 * - base_theme: If this is a sub-theme, the machine name of the base theme
76 * defined in the .info.yml file. Otherwise, the element is not set.
77 * - base_themes: If this is a sub-theme, an associative array of the
78 * base-theme ancestors of this theme, starting with this theme's base
79 * theme, then the base theme's own base theme, etc. Each entry has an
80 * array key equal to the theme's machine name, and a value equal to the
81 * human-readable theme name; if a theme with matching machine name does
82 * not exist in the system, the value will instead be NULL (and since the
83 * system would not know whether that theme itself has a base theme, that
84 * will end the array of base themes). This is not set if the theme is not
86 * - sub_themes: An associative array of themes on the system that are
87 * either direct sub-themes (that is, they declare this theme to be
88 * their base theme), direct sub-themes of sub-themes, etc. The keys are
89 * the themes' machine names, and the values are the themes'
90 * human-readable names. This element is not set if there are no themes on
91 * the system that declare this theme as their base theme.
93 public function listInfo();
96 * Adds a theme extension to the internal listing.
98 * @param \Drupal\Core\Extension\Extension $theme
99 * The theme extension.
101 public function addTheme(Extension $theme);
104 * Refreshes the theme info data of currently installed themes.
106 * Modules can alter theme info, so this is typically called after a module
107 * has been installed or uninstalled.
109 public function refreshInfo();
112 * Resets the internal state of the theme handler.
114 public function reset();
117 * Scans and collects theme extension data and their engines.
119 * @return \Drupal\Core\Extension\Extension[]
120 * An associative array of theme extensions.
122 public function rebuildThemeData();
125 * Finds all the base themes for the specified theme.
127 * Themes can inherit templates and function implementations from earlier
130 * @param \Drupal\Core\Extension\Extension[] $themes
131 * An array of available themes.
132 * @param string $theme
133 * The name of the theme whose base we are looking for.
136 * Returns an array of all of the theme's ancestors; the first element's
137 * value will be NULL if an error occurred.
139 public function getBaseThemes(array $themes, $theme);
142 * Gets the human readable name of a given theme.
144 * @param string $theme
145 * The machine name of the theme which title should be shown.
148 * Returns the human readable name of the theme.
150 * @throws \Drupal\Core\Extension\Exception\UnknownExtensionException
151 * When the specified theme does not exist.
153 public function getName($theme);
156 * Returns the default theme.
161 public function getDefault();
164 * Sets a new default theme.
166 * @param string $theme
167 * The new default theme.
171 * @deprecated in Drupal 8.2.x-dev and will be removed before Drupal 9.0.0.
174 * \Drupal::configFactory()
175 * ->getEditable('system.theme')
176 * ->set('default', $theme)
180 public function setDefault($theme);
183 * Returns an array of directories for all installed themes.
185 * Useful for tasks such as finding a file that exists in all theme
190 public function getThemeDirectories();
193 * Determines whether a given theme is installed.
195 * @param string $theme
196 * The name of the theme (without the .theme extension).
199 * TRUE if the theme is installed.
201 public function themeExists($theme);
204 * Returns a theme extension object from the currently active theme list.
206 * @param string $name
207 * The name of the theme to return.
209 * @return \Drupal\Core\Extension\Extension
210 * An extension object.
212 * @throws \Drupal\Core\Extension\Extension\UnknownExtensionException
213 * Thrown when the requested theme does not exist.
215 public function getTheme($name);
218 * Determines if a theme should be shown in the user interface.
220 * To be shown in the UI the theme has to be installed. If the theme is hidden
221 * it will not be shown unless it is the default or admin theme.
223 * @param string $name
224 * The name of the theme to check.
227 * TRUE if the theme should be shown in the UI, FALSE if not.
229 public function hasUi($name);