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 \InvalidArgumentException
43 * Thrown when you uninstall an not installed theme.
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();
97 * Adds a theme extension to the internal listing.
99 * @param \Drupal\Core\Extension\Extension $theme
100 * The theme extension.
102 public function addTheme(Extension $theme);
105 * Refreshes the theme info data of currently installed themes.
107 * Modules can alter theme info, so this is typically called after a module
108 * has been installed or uninstalled.
110 public function refreshInfo();
113 * Resets the internal state of the theme handler.
115 public function reset();
118 * Scans and collects theme extension data and their engines.
120 * @return \Drupal\Core\Extension\Extension[]
121 * An associative array of theme extensions.
123 public function rebuildThemeData();
126 * Finds all the base themes for the specified theme.
128 * Themes can inherit templates and function implementations from earlier
131 * @param \Drupal\Core\Extension\Extension[] $themes
132 * An array of available themes.
133 * @param string $theme
134 * The name of the theme whose base we are looking for.
137 * Returns an array of all of the theme's ancestors; the first element's
138 * value will be NULL if an error occurred.
140 public function getBaseThemes(array $themes, $theme);
143 * Gets the human readable name of a given theme.
145 * @param string $theme
146 * The machine name of the theme which title should be shown.
149 * Returns the human readable name of the theme.
151 public function getName($theme);
154 * Returns the default theme.
159 public function getDefault();
162 * Sets a new default theme.
164 * @param string $theme
165 * The new default theme.
169 * @deprecated in Drupal 8.2.x-dev and will be removed before Drupal 9.0.0.
172 * \Drupal::configFactory()
173 * ->getEditable('system.theme')
174 * ->set('default', $theme)
178 public function setDefault($theme);
181 * Returns an array of directories for all installed themes.
183 * Useful for tasks such as finding a file that exists in all theme
188 public function getThemeDirectories();
191 * Determines whether a given theme is installed.
193 * @param string $theme
194 * The name of the theme (without the .theme extension).
197 * TRUE if the theme is installed.
199 public function themeExists($theme);
202 * Returns a theme extension object from the currently active theme list.
204 * @param string $name
205 * The name of the theme to return.
207 * @return \Drupal\Core\Extension\Extension
208 * An extension object.
210 * @throws \InvalidArgumentException
211 * Thrown when the requested theme does not exist.
213 public function getTheme($name);
216 * Determines if a theme should be shown in the user interface.
218 * To be shown in the UI the theme has to be installed. If the theme is hidden
219 * it will not be shown unless it is the default or admin theme.
221 * @param string $name
222 * The name of the theme to check.
225 * TRUE if the theme should be shown in the UI, FALSE if not.
227 public function hasUi($name);