5 * Contains \Drupal\Console\Command\Theme\InstallCommand.
8 namespace Drupal\Console\Command\Theme;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputOption;
12 use Symfony\Component\Console\Input\InputInterface;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Symfony\Component\Console\Command\Command;
15 use Drupal\Console\Core\Command\Shared\CommandTrait;
16 use Drupal\Core\Config\ConfigFactory;
17 use Drupal\Core\Extension\ThemeHandler;
18 use Drupal\Core\Config\UnmetDependenciesException;
19 use Drupal\Console\Core\Style\DrupalStyle;
20 use Drupal\Console\Core\Utils\ChainQueue;
22 class InstallCommand extends Command
29 protected $configFactory;
34 protected $themeHandler;
39 protected $chainQueue;
42 * DebugCommand constructor.
44 * @param ConfigFactory $configFactory
45 * @param ThemeHandler $themeHandler
46 * @param ChainQueue $chainQueue
48 public function __construct(
49 ConfigFactory $configFactory,
50 ThemeHandler $themeHandler,
51 ChainQueue $chainQueue
53 $this->configFactory = $configFactory;
54 $this->themeHandler = $themeHandler;
55 $this->chainQueue = $chainQueue;
56 parent::__construct();
59 protected function configure()
62 ->setName('theme:install')
63 ->setDescription($this->trans('commands.theme.install.description'))
64 ->addArgument('theme', InputArgument::IS_ARRAY, $this->trans('commands.theme.install.options.module'))
68 InputOption::VALUE_NONE,
69 $this->trans('commands.theme.install.options.set-default')
76 protected function interact(InputInterface $input, OutputInterface $output)
78 $io = new DrupalStyle($input, $output);
80 $theme = $input->getArgument('theme');
85 $themes = $this->themeHandler->rebuildThemeData();
87 foreach ($themes as $theme_id => $theme) {
88 if (!empty($theme->info['hidden'])) {
96 $theme_list[$theme_id] = $theme->getName();
99 $io->info($this->trans('commands.theme.install.messages.disabled-themes'));
102 $theme_name = $io->choiceNoList(
103 $this->trans('commands.theme.install.questions.theme'),
104 array_keys($theme_list)
107 if (empty($theme_name)) {
111 $theme_list_install[] = $theme_name;
113 if (array_search($theme_name, $theme_list_install, true) >= 0) {
114 unset($theme_list[$theme_name]);
118 $input->setArgument('theme', $theme_list_install);
122 protected function execute(InputInterface $input, OutputInterface $output)
124 $io = new DrupalStyle($input, $output);
126 $config = $this->configFactory->getEditable('system.theme');
128 $this->themeHandler->refreshInfo();
129 $theme = $input->getArgument('theme');
130 $default = $input->getOption('set-default');
132 if ($default && count($theme) > 1) {
133 $io->error($this->trans('commands.theme.install.messages.invalid-theme-default'));
138 $themes = $this->themeHandler->rebuildThemeData();
139 $themesAvailable = [];
140 $themesInstalled = [];
141 $themesUnavailable = [];
143 foreach ($theme as $themeName) {
144 if (isset($themes[$themeName]) && $themes[$themeName]->status == 0) {
145 $themesAvailable[] = $themes[$themeName]->info['name'];
146 } elseif (isset($themes[$themeName]) && $themes[$themeName]->status == 1) {
147 $themesInstalled[] = $themes[$themeName]->info['name'];
149 $themesUnavailable[] = $themeName;
153 if (count($themesAvailable) > 0) {
155 if ($this->themeHandler->install($theme)) {
156 if (count($themesAvailable) > 1) {
159 $this->trans('commands.theme.install.messages.themes-success'),
160 implode(',', $themesAvailable)
165 // Set the default theme.
166 $config->set('default', $theme[0])->save();
169 $this->trans('commands.theme.install.messages.theme-default-success'),
176 $this->trans('commands.theme.install.messages.theme-success'),
183 } catch (UnmetDependenciesException $e) {
186 $this->trans('commands.theme.install.messages.success'),
190 drupal_set_message($e->getTranslatedMessage($this->getStringTranslation(), $theme), 'error');
194 } elseif (empty($themesAvailable) && count($themesInstalled) > 0) {
195 if (count($themesInstalled) > 1) {
198 $this->trans('commands.theme.install.messages.themes-nothing'),
199 implode(',', $themesInstalled)
205 $this->trans('commands.theme.install.messages.theme-nothing'),
206 implode(',', $themesInstalled)
211 if (count($themesUnavailable) > 1) {
214 $this->trans('commands.theme.install.messages.themes-missing'),
215 implode(',', $themesUnavailable)
221 $this->trans('commands.theme.install.messages.theme-missing'),
222 implode(',', $themesUnavailable)
228 // Run cache rebuild to see changes in Web UI
229 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);