public function ThemeInstaller::uninstall in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Extension/ThemeInstaller.php \Drupal\Core\Extension\ThemeInstaller::uninstall()
Uninstalls a given list of themes.
Uninstalling a theme removes all related configuration (like blocks) and invokes the 'themes_uninstalled' hook.
Parameters
array $theme_list: The themes to uninstall.
Throws
\InvalidArgumentException Thrown when you uninstall an not installed theme.
Overrides ThemeInstallerInterface::uninstall
See also
File
- core/
lib/ Drupal/ Core/ Extension/ ThemeInstaller.php, line 219 - Contains \Drupal\Core\Extension\ThemeInstaller.
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();
foreach ($theme_list as $key) {
if (!isset($list[$key])) {
throw new \InvalidArgumentException("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 admin 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.
// @todo https://www.drupal.org/node/474684 and
// https://www.drupal.org/node/1297856 themes should leverage the module
// dependency system.
if (!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();
$current_theme_data = $this->state
->get('system.theme.data', array());
foreach ($theme_list as $key) {
// The value is not used; the weight is ignored for themes currently.
$extension_config
->clear("theme.{$key}");
// Update the current theme data accordingly.
unset($current_theme_data[$key]);
// Reset theme settings.
$theme_settings =& drupal_static('theme_get_setting');
unset($theme_settings[$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);
$this->state
->set('system.theme.data', $current_theme_data);
// @todo Remove system_list().
$this->themeHandler
->refreshInfo();
$this
->resetSystem();
$this->moduleHandler
->invokeAll('themes_uninstalled', [
$theme_list,
]);
}