5 * Contains \Drupal\Console\Command\Theme\Debugommand.
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\Console\Core\Style\DrupalStyle;
19 class DebugCommand extends Command
26 protected $configFactory;
31 protected $themeHandler;
34 * DebugCommand constructor.
36 * @param ConfigFactory $configFactory
37 * @param ThemeHandler $themeHandler
39 public function __construct(
40 ConfigFactory $configFactory,
41 ThemeHandler $themeHandler
43 $this->configFactory = $configFactory;
44 $this->themeHandler = $themeHandler;
45 parent::__construct();
48 protected function configure()
51 ->setName('theme:debug')
52 ->setDescription($this->trans('commands.theme.debug.description'))
53 ->addArgument('theme', InputArgument::OPTIONAL, $this->trans('commands.theme.debug.arguments.theme'));
56 protected function execute(InputInterface $input, OutputInterface $output)
58 $io = new DrupalStyle($input, $output);
60 $theme = $input->getArgument('theme');
62 $this->themeDetail($io, $theme);
64 $this->themeList($io);
68 protected function themeList(DrupalStyle $io)
71 $this->trans('commands.theme.debug.messages.theme-id'),
72 $this->trans('commands.theme.debug.messages.theme-name'),
73 $this->trans('commands.theme.debug.messages.status'),
74 $this->trans('commands.theme.debug.messages.version'),
77 $themes = $this->themeHandler->rebuildThemeData();
79 foreach ($themes as $themeId => $theme) {
80 $status = $this->getThemeStatus($theme);
82 $themeId, $theme->info['name'],
83 $status, $theme->info['version'],
87 $io->table($tableHeader, $tableRows);
90 protected function themeDetail(DrupalStyle $io, $themeId)
93 $themes = $this->themeHandler->rebuildThemeData();
95 if (isset($themes[$themeId])) {
96 $theme = $themes[$themeId];
98 foreach ($themes as $themeAvailableId => $themeAvailable) {
99 if ($themeAvailable->info['name'] == $themeId) {
100 $themeId = $themeAvailableId;
101 $theme = $themeAvailable;
108 $theme = $themes[$themeId];
109 $status = $this->getThemeStatus($themeId);
111 $io->info($theme->info['name']);
116 $this->trans('commands.theme.debug.messages.status')
120 $io->writeln($status);
124 $this->trans('commands.theme.debug.messages.version')
128 $io->writeln($theme->info['version']);
129 $io->comment($this->trans('commands.theme.debug.messages.regions'));
130 $tableRows = $this->addThemeAttributes($theme->info['regions'], $tableRows);
131 $io->table([], $tableRows);
135 $this->trans('commands.theme.debug.messages.invalid-theme'),
142 protected function getThemeStatus($theme)
144 $defaultTheme = $this->configFactory->get('system.theme')->get('default');
146 $status = ($theme->status)?$this->trans('commands.theme.debug.messages.installed'):$this->trans('commands.theme.debug.messages.uninstalled');
147 if ($defaultTheme == $theme) {
148 $status = $this->trans('commands.theme.debug.messages.default-theme');
154 protected function addThemeAttributes($attr, $tableRows = [])
156 foreach ($attr as $key => $value) {
157 if (is_array($value)) {
158 $tableRows = $this->addThemeAttributes($value, $tableRows);