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