You are here

public function ThemeInstaller::uninstall in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Extension/ThemeInstaller.php \Drupal\Core\Extension\ThemeInstaller::uninstall()
  2. 9 core/lib/Drupal/Core/Extension/ThemeInstaller.php \Drupal\Core\Extension\ThemeInstaller::uninstall()

File

core/lib/Drupal/Core/Extension/ThemeInstaller.php, line 251

Class

ThemeInstaller
Manages theme installation/uninstallation.

Namespace

Drupal\Core\Extension

Code

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 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 (!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}");

    // 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);

  // Refresh theme info.
  $this
    ->resetSystem();
  $this->themeHandler
    ->reset();
  $this->moduleHandler
    ->invokeAll('themes_uninstalled', [
    $theme_list,
  ]);
}