Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / src / Command / Entity / DebugCommand.php
1 <?php
2 /**
3  * @file
4  * Contains \Drupal\Console\Command\Entity\DebugCommand.
5  */
6
7 namespace Drupal\Console\Command\Entity;
8
9 use Symfony\Component\Console\Input\InputArgument;
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Console\Command\Command;
13 use Drupal\Core\Entity\EntityTypeRepository;
14 use Drupal\Core\Entity\EntityTypeManagerInterface;
15 use Drupal\Console\Core\Command\Shared\CommandTrait;
16 use Drupal\Console\Core\Style\DrupalStyle;
17
18 class DebugCommand extends Command
19 {
20     use CommandTrait;
21
22     /**
23      * @var EntityTypeRepository
24      */
25     protected $entityTypeRepository;
26
27     /**
28      * @var EntityTypeManagerInterface
29      */
30     protected $entityTypeManager;
31
32     /**
33      * DeleteCommand constructor.
34      *
35      * @param EntityTypeRepository       $entityTypeRepository
36      * @param EntityTypeManagerInterface $entityTypeManager
37      */
38     public function __construct(
39         EntityTypeRepository $entityTypeRepository,
40         EntityTypeManagerInterface $entityTypeManager
41     ) {
42         $this->entityTypeRepository = $entityTypeRepository;
43         $this->entityTypeManager = $entityTypeManager;
44         parent::__construct();
45     }
46     /**
47      * {@inheritdoc}
48      */
49     protected function configure()
50     {
51         $this
52             ->setName('entity:debug')
53             ->setDescription($this->trans('commands.entity.debug.description'))
54             ->addArgument(
55                 'entity-type',
56                 InputArgument::OPTIONAL,
57                 $this->trans('commands.entity.debug.arguments.entity-type')
58             );
59     }
60
61     /**
62      * {@inheritdoc}
63      */
64     protected function execute(InputInterface $input, OutputInterface $output)
65     {
66         $io = new DrupalStyle($input, $output);
67
68         $entityType = $input->getArgument('entity-type');
69
70         $tableHeader = [
71             $this->trans('commands.entity.debug.table-headers.entity-name'),
72             $this->trans('commands.entity.debug.table-headers.entity-type')
73         ];
74         $tableRows = [];
75
76         $entityTypesLabels = $this->entityTypeRepository->getEntityTypeLabels(true);
77
78         if ($entityType) {
79             $entityTypes = [$entityType => $entityType];
80         } else {
81             $entityTypes = array_keys($entityTypesLabels);
82         }
83
84         foreach ($entityTypes as $entityTypeId) {
85             $entities = array_keys($entityTypesLabels[$entityTypeId]);
86             foreach ($entities as $entity) {
87                 $tableRows[$entity] = [
88                     $entity,
89                     $entityTypeId
90                 ];
91             }
92         }
93
94         $io->table($tableHeader, array_values($tableRows));
95     }
96 }