5 * Contains \Drupal\Console\Command\Theme\DebugKeysCommand.
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 Symfony\Component\Yaml\Yaml;
14 use Drupal\Console\Core\Command\Command;
15 use Drupal\Console\Core\Command\Shared\CommandTrait;
16 use Drupal\Core\Theme\Registry;
18 class ThemeKeysCommand extends Command
25 protected $themeRegistry;
28 * DebugCommand constructor.
30 * @param \Drupal\Core\Theme\Registry $themeRegistry
31 * The theme registry service.
33 public function __construct(Registry $themeRegistry)
35 $this->themeRegistry = $themeRegistry;
36 parent::__construct();
39 protected function configure()
42 ->setName('debug:theme:keys')
43 ->setDescription($this->trans('commands.debug.theme.keys.description'))
44 ->setHelp($this->trans('commands.debug.theme.keys.help'))
47 InputArgument::OPTIONAL,
48 $this->trans('commands.debug.theme.keys.arguments.key')
50 ->setAliases(['dtk']);
53 protected function execute(InputInterface $input, OutputInterface $output)
55 $key = $input->getArgument('key');
58 $this->themeKeysList();
60 $this->themeKeysDetail($key);
64 protected function themeKeysList()
67 $this->trans('commands.debug.theme.keys.table-headers.key'),
68 $this->trans('commands.debug.theme.keys.table-headers.provider-type'),
69 $this->trans('commands.debug.theme.keys.table-headers.provider'),
73 $keys = $this->themeRegistry->get();
74 foreach ($keys as $key => $definition) {
77 $this->trans('commands.debug.theme.keys.provider-types.' . strtr($definition['type'], '_', '-')),
78 basename($definition['theme path']),
81 array_multisort($tableRows, array_column($tableRows, 0));
83 $this->getIo()->table($tableHeader, $tableRows);
86 protected function themeKeysDetail($key)
89 $this->trans('commands.debug.theme.keys.table-headers.key'),
90 $this->trans('commands.debug.theme.keys.table-headers.value')
93 $keys = $this->themeRegistry->get();
94 $definition = $keys[$key];
97 foreach ($definition as $key => $value) {
98 if (is_object($value) && method_exists($value, '__toString')) {
99 $value = (string) $value;
100 } elseif (is_array($value) || is_object($value)) {
101 $value = Yaml::dump($value);
102 } elseif (is_bool($value)) {
103 $value = ($value) ? 'TRUE' : 'FALSE';
105 $tableRows[$key] = [$key, $value];
108 $this->getIo()->table($tableHeader, array_values($tableRows));