function ThemeInstaller::uninstall
Uninstalls a given list of themes.
Uninstalling a theme removes all related configuration (like blocks) and invokes the 'themes_uninstalled' hook.
Themes are allowed to be uninstalled even when their code has been removed from the filesystem, this is because themes do not allow uninstall hooks to be defined.
Parameters
array $theme_list: The themes to uninstall.
Overrides ThemeInstallerInterface::uninstall
File
-
core/
lib/ Drupal/ Core/ Extension/ ThemeInstaller.php, line 193
Class
- ThemeInstaller
- Manages theme installation/uninstallation.
Namespace
Drupal\Core\ExtensionCode
public function uninstall(array $theme_list) {
$extension_config = $this->configFactory
->getEditable('core.extension');
$theme_config = $this->configFactory
->getEditable('system.theme');
$list = $this->themeHandler
->listInfo();
$installed_themes = $extension_config->get('theme') ?: [];
$theme_data = $this->themeExtensionList
->reset()
->getList();
foreach ($theme_list as $key) {
if ($extension_config->get("theme.{$key}") === NULL) {
throw new UnknownExtensionException("Unknown theme: {$key}.");
}
if ($key === $theme_config->get('default')) {
throw new \InvalidArgumentException("The current default theme {$key} cannot be uninstalled.");
}
if ($key === $theme_config->get('admin')) {
throw new \InvalidArgumentException("The current administration theme {$key} cannot be uninstalled.");
}
// Base themes cannot be uninstalled if sub themes are installed, and if
// they are not uninstalled at the same time.
if (isset($list[$key]) && !empty($list[$key]->sub_themes)) {
foreach ($list[$key]->sub_themes as $sub_key => $sub_label) {
if (isset($list[$sub_key]) && !in_array($sub_key, $theme_list, TRUE)) {
throw new \InvalidArgumentException("The base theme {$key} cannot be uninstalled, because theme {$sub_key} depends on it.");
}
}
}
}
$this->cssCollectionOptimizer
->deleteAll();
foreach ($theme_list as $key) {
// The value is not used; the weight is ignored for themes currently.
$extension_config->clear("theme.{$key}");
// Remove all configuration belonging to the theme.
$this->configManager
->uninstall('theme', $key);
}
// Don't check schema when uninstalling a theme since we are only clearing
// keys.
$extension_config->save(TRUE);
// Refresh theme info.
$this->themeHandler
->reset();
// Remove themes that were uninstalled from the list.
$register_themes = array_diff(array_keys($installed_themes), $theme_list);
// Get list of extensions for the new list of themes.
$register_themes = array_intersect_key($theme_data, array_flip($register_themes));
$this->resetSystem($register_themes);
$this->moduleHandler
->invokeAll('themes_uninstalled', [
$theme_list,
]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.