function ThemeInstaller::getThemesToUninstall

File

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

Class

ThemeInstaller
Manages theme installation/uninstallation.

Namespace

Drupal\Core\Extension

Code

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.