Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / src / Command / Views / PluginsDebugCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Views\PluginsDebugCommand.
6  */
7
8 namespace Drupal\Console\Command\Views;
9
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\ContainerAwareCommandTrait;
15 use Drupal\Console\Core\Style\DrupalStyle;
16 use Drupal\views\Views;
17
18 /**
19  * Class PluginsDebugCommand
20  *
21  * @package Drupal\Console\Command\Views
22  */
23 class PluginsDebugCommand extends Command
24 {
25     use ContainerAwareCommandTrait;
26     /**
27      * {@inheritdoc}
28      */
29     protected function configure()
30     {
31         $this
32             ->setName('views:plugins:debug')
33             ->setDescription($this->trans('commands.views.plugins.debug.description'))
34             ->addArgument(
35                 'type',
36                 InputArgument::OPTIONAL,
37                 $this->trans('commands.views.plugins.debug.arguments.type')
38             );
39     }
40
41     /**
42      * {@inheritdoc}
43      */
44     protected function execute(InputInterface $input, OutputInterface $output)
45     {
46         $io = new DrupalStyle($input, $output);
47         $type = $input->getArgument('type');
48
49         $this->pluginList($io, $type);
50     }
51
52     /**
53      * @param \Drupal\Console\Core\Style\DrupalStyle $io
54      * @param $type
55      */
56     protected function pluginList(DrupalStyle $io, $type)
57     {
58         $plugins = Views::pluginList();
59
60         $rows = [];
61         foreach ($plugins as &$plugin) {
62             if ($type && $plugin['type'] != $type) {
63                 continue;
64             }
65
66             $views = [];
67             // Link each view name to the view itself.
68             foreach ($plugin['views'] as $plugin_name => $view) {
69                 $views[] = $view;
70             }
71             $rows[] = [$plugin['type'], $plugin['title'], $plugin['provider'], implode(",", $views)];
72         }
73
74         // Sort rows by field name.
75         ksort($rows);
76
77
78         $tableHeader = [
79           $this->trans('commands.views.plugins.debug.messages.type'),
80           $this->trans('commands.views.plugins.debug.messages.name'),
81           $this->trans('commands.views.plugins.debug.messages.provider'),
82           $this->trans('commands.views.plugins.debug.messages.views'),
83         ];
84
85         $io->table($tableHeader, $rows, 'compact');
86     }
87 }