5 * Contains \Drupal\Console\Command\Theme\UninstallCommand.
8 namespace Drupal\Console\Command\Theme;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\Console\Command\Command;
14 use Drupal\Console\Core\Command\Shared\CommandTrait;
15 use Drupal\Core\Config\ConfigFactory;
16 use Drupal\Core\Extension\ThemeHandler;
17 use Drupal\Core\Config\UnmetDependenciesException;
18 use Drupal\Console\Core\Style\DrupalStyle;
19 use Drupal\Console\Core\Utils\ChainQueue;
21 class UninstallCommand extends Command
28 protected $configFactory;
33 protected $themeHandler;
38 protected $chainQueue;
41 * DebugCommand constructor.
43 * @param ConfigFactory $configFactory
44 * @param ThemeHandler $themeHandler
45 * @param ChainQueue $chainQueue
47 public function __construct(
48 ConfigFactory $configFactory,
49 ThemeHandler $themeHandler,
50 ChainQueue $chainQueue
52 $this->configFactory = $configFactory;
53 $this->themeHandler = $themeHandler;
54 $this->chainQueue = $chainQueue;
55 parent::__construct();
58 protected function configure()
61 ->setName('theme:uninstall')
62 ->setDescription($this->trans('commands.theme.uninstall.description'))
63 ->addArgument('theme', InputArgument::IS_ARRAY, $this->trans('commands.theme.uninstall.options.module'));
69 protected function interact(InputInterface $input, OutputInterface $output)
71 $io = new DrupalStyle($input, $output);
73 $theme = $input->getArgument('theme');
78 $themes = $this->themeHandler->rebuildThemeData();
80 foreach ($themes as $theme_id => $theme) {
81 if (!empty($theme->info['hidden'])) {
85 if (!empty($theme->status == 0)) {
88 $theme_list[$theme_id] = $theme->getName();
91 $io->info($this->trans('commands.theme.uninstall.messages.installed-themes'));
94 $theme_name = $io->choiceNoList(
95 $this->trans('commands.theme.uninstall.questions.theme'),
96 array_keys($theme_list)
99 if (empty($theme_name)) {
103 $theme_list_install[] = $theme_name;
105 if (array_search($theme_name, $theme_list_install, true) >= 0) {
106 unset($theme_list[$theme_name]);
110 $input->setArgument('theme', $theme_list_install);
114 protected function execute(InputInterface $input, OutputInterface $output)
116 $io = new DrupalStyle($input, $output);
118 $config = $this->configFactory->getEditable('system.theme');
120 $this->themeHandler->refreshInfo();
121 $theme = $input->getArgument('theme');
123 $themes = $this->themeHandler->rebuildThemeData();
124 $themesAvailable = [];
125 $themesUninstalled = [];
126 $themesUnavailable = [];
128 foreach ($theme as $themeName) {
129 if (isset($themes[$themeName]) && $themes[$themeName]->status == 1) {
130 $themesAvailable[$themeName] = $themes[$themeName]->info['name'];
131 } elseif (isset($themes[$themeName]) && $themes[$themeName]->status == 0) {
132 $themesUninstalled[] = $themes[$themeName]->info['name'];
134 $themesUnavailable[] = $themeName;
138 if (count($themesAvailable) > 0) {
140 foreach ($themesAvailable as $themeKey => $themeName) {
141 if ($themeKey === $config->get('default')) {
144 $this->trans('commands.theme.uninstall.messages.error-default-theme'),
145 implode(',', $themesAvailable)
152 if ($themeKey === $config->get('admin')) {
155 $this->trans('commands.theme.uninstall.messages.error-admin-theme'),
156 implode(',', $themesAvailable)
163 $this->themeHandler->uninstall($theme);
165 if (count($themesAvailable) > 1) {
168 $this->trans('commands.theme.uninstall.messages.themes-success'),
169 implode(',', $themesAvailable)
175 $this->trans('commands.theme.uninstall.messages.theme-success'),
176 array_shift($themesAvailable)
180 } catch (UnmetDependenciesException $e) {
183 $this->trans('commands.theme.uninstall.messages.dependencies'),
187 drupal_set_message($e->getTranslatedMessage($this->getStringTranslation(), $theme), 'error');
191 } elseif (empty($themesAvailable) && count($themesUninstalled) > 0) {
192 if (count($themesUninstalled) > 1) {
195 $this->trans('commands.theme.uninstall.messages.themes-nothing'),
196 implode(',', $themesUninstalled)
202 $this->trans('commands.theme.uninstall.messages.theme-nothing'),
203 implode(',', $themesUninstalled)
208 if (count($themesUnavailable) > 1) {
211 $this->trans('commands.theme.uninstall.messages.themes-missing'),
212 implode(',', $themesUnavailable)
218 $this->trans('commands.theme.uninstall.messages.theme-missing'),
219 implode(',', $themesUnavailable)
225 // Run cache rebuild to see changes in Web UI
226 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);