function ThemeInstaller::getThemesToUninstall
Determines the full set of themes to uninstall for the given list.
Parameters
string[] $theme_list: An array of theme machine names.
bool $uninstall_dependents: (optional) If TRUE, installed sub-themes of the given themes are added to the returned list. If FALSE, an exception is thrown when a given base theme has an installed sub-theme that is not also in the list.
Return value
string[] The machine names of the themes to uninstall, including any added sub-themes.
Overrides ThemeInstallerInterface::getThemesToUninstall
1 call to ThemeInstaller::getThemesToUninstall()
- ThemeInstaller::uninstall in core/
lib/ Drupal/ Core/ Extension/ ThemeInstaller.php - Uninstalls a given list of themes.
File
-
core/
lib/ Drupal/ Core/ Extension/ ThemeInstaller.php, line 215
Class
- ThemeInstaller
- Manages theme installation/uninstallation.
Namespace
Drupal\Core\ExtensionCode
public function getThemesToUninstall(array $theme_list, bool $uninstall_dependents = TRUE) : array {
$extension_config = $this->configFactory
->get('core.extension');
$theme_config = $this->configFactory
->get('system.theme');
$list = $this->themeHandler
->listInfo();
$theme_list = array_combine(array_values($theme_list), array_values($theme_list));
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, unless
// they are uninstalled at the same time.
foreach (array_keys($list[$key]->sub_themes ?? []) as $sub_key) {
if (isset($list[$sub_key]) && !isset($theme_list[$sub_key])) {
if (!$uninstall_dependents) {
throw new \InvalidArgumentException("The base theme {$key} cannot be uninstalled, because theme {$sub_key} depends on it.");
}
$theme_list[$sub_key] = $sub_key;
}
}
}
return array_values($theme_list);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.