function ThemeInstaller::uninstall

Same name in other branches
  1. 9 core/lib/Drupal/Core/Extension/ThemeInstaller.php \Drupal\Core\Extension\ThemeInstaller::uninstall()
  2. 10 core/lib/Drupal/Core/Extension/ThemeInstaller.php \Drupal\Core\Extension\ThemeInstaller::uninstall()
  3. 11.x core/lib/Drupal/Core/Extension/ThemeInstaller.php \Drupal\Core\Extension\ThemeInstaller::uninstall()

Overrides ThemeInstallerInterface::uninstall

File

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

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.
        // @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();
    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,
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.