5 * Contains \Drupal\Console\Command\Debug\ThemeCommand.
8 namespace Drupal\Console\Command\Debug;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Drupal\Console\Core\Command\Command;
14 use Drupal\Core\Config\ConfigFactory;
15 use Drupal\Core\Extension\ThemeHandler;
17 class ThemeCommand extends Command
22 protected $configFactory;
27 protected $themeHandler;
30 * DebugCommand constructor.
32 * @param ConfigFactory $configFactory
33 * @param ThemeHandler $themeHandler
35 public function __construct(
36 ConfigFactory $configFactory,
37 ThemeHandler $themeHandler
39 $this->configFactory = $configFactory;
40 $this->themeHandler = $themeHandler;
41 parent::__construct();
44 protected function configure()
47 ->setName('debug:theme')
48 ->setDescription($this->trans('commands.debug.theme.description'))
51 InputArgument::OPTIONAL,
52 $this->trans('commands.debug.theme.arguments.theme')
57 protected function execute(InputInterface $input, OutputInterface $output)
59 $theme = $input->getArgument('theme');
61 $this->themeDetail($theme);
67 protected function themeList()
70 $this->trans('commands.debug.theme.messages.theme-id'),
71 $this->trans('commands.debug.theme.messages.theme-name'),
72 $this->trans('commands.debug.theme.messages.status'),
73 $this->trans('commands.debug.theme.messages.version'),
76 $themes = $this->themeHandler->rebuildThemeData();
78 foreach ($themes as $themeId => $theme) {
79 $status = $this->getThemeStatus($theme);
84 (isset($theme->info['version'])) ? $theme->info['version'] : '',
88 $this->getIo()->table($tableHeader, $tableRows);
91 protected function themeDetail($themeId)
94 $themes = $this->themeHandler->rebuildThemeData();
96 if (isset($themes[$themeId])) {
97 $theme = $themes[$themeId];
99 foreach ($themes as $themeAvailableId => $themeAvailable) {
100 if ($themeAvailable->info['name'] == $themeId) {
101 $themeId = $themeAvailableId;
102 $theme = $themeAvailable;
109 $theme = $themes[$themeId];
110 $status = $this->getThemeStatus($themeId);
112 $this->getIo()->info($theme->info['name']);
114 $this->getIo()->comment(
117 $this->trans('commands.debug.theme.messages.status')
121 $this->getIo()->writeln($status);
122 $this->getIo()->comment(
125 $this->trans('commands.debug.theme.messages.version')
129 $this->getIo()->writeln($theme->info['version']);
130 $this->getIo()->comment($this->trans('commands.debug.theme.messages.regions'));
131 $tableRows = $this->addThemeAttributes($theme->info['regions'], $tableRows);
132 $this->getIo()->table([], $tableRows);
134 $this->getIo()->error(
136 $this->trans('commands.debug.theme.messages.invalid-theme'),
143 protected function getThemeStatus($theme)
145 $defaultTheme = $this->configFactory->get('system.theme')->get('default');
147 $status = ($theme->status)?$this->trans('commands.debug.theme.messages.installed'):$this->trans('commands.debug.theme.messages.uninstalled');
148 if ($defaultTheme == $theme) {
149 $status = $this->trans('commands.debug.theme.messages.default-theme');
155 protected function addThemeAttributes($attr, $tableRows = [])
157 foreach ($attr as $key => $value) {
158 if (is_array($value)) {
159 $tableRows = $this->addThemeAttributes($value, $tableRows);