Skip to content

Commit a68301c

Browse files
authored
entity:debug New command (#2952)
* Add new command entity:debug * New command entity:debug
1 parent 73fc485 commit a68301c

2 files changed

Lines changed: 100 additions & 0 deletions

File tree

config/services/drupal-console/entity.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
services:
2+
console.entity_debug:
3+
class: Drupal\Console\Command\Entity\DebugCommand
4+
arguments: ['@entity_type.repository', '@entity_type.manager']
5+
tags:
6+
- { name: drupal.command }
27
console.entity_delete:
38
class: Drupal\Console\Command\Entity\DeleteCommand
49
arguments: ['@entity_type.repository', '@entity_type.manager']
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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\Command\Shared\CommandTrait;
16+
use Drupal\Console\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+
* @param EntityTypeRepository $entityTypeRepository
35+
* @param EntityTypeManagerInterface $entityTypeManager
36+
*/
37+
public function __construct(
38+
EntityTypeRepository $entityTypeRepository,
39+
EntityTypeManagerInterface $entityTypeManager
40+
) {
41+
$this->entityTypeRepository = $entityTypeRepository;
42+
$this->entityTypeManager = $entityTypeManager;
43+
parent::__construct();
44+
}
45+
/**
46+
* {@inheritdoc}
47+
*/
48+
protected function configure()
49+
{
50+
$this
51+
->setName('entity:debug')
52+
->setDescription($this->trans('commands.entity.debug.description'))
53+
->addArgument(
54+
'entity-type',
55+
InputArgument::OPTIONAL,
56+
$this->trans('commands.entity.debug.arguments.entity-type')
57+
);
58+
}
59+
60+
/**
61+
* {@inheritdoc}
62+
*/
63+
protected function execute(InputInterface $input, OutputInterface $output)
64+
{
65+
$io = new DrupalStyle($input, $output);
66+
67+
$entityType = $input->getArgument('entity-type');
68+
69+
$tableHeader = [
70+
$this->trans('commands.entity.debug.table-headers.entity-name'),
71+
$this->trans('commands.entity.debug.table-headers.entity-type')
72+
];
73+
$tableRows = [];
74+
75+
$entityTypesLabels = $this->entityTypeRepository->getEntityTypeLabels(true);
76+
77+
if ($entityType) {
78+
$entityTypes = [$entityType => $entityType];
79+
} else {
80+
$entityTypes = array_keys($entityTypesLabels);
81+
}
82+
83+
foreach($entityTypes as $entityTypeId){
84+
$entities = array_keys($entityTypesLabels[$entityTypeId]);
85+
foreach($entities as $entity) {
86+
$tableRows[$entity] = [
87+
$entity,
88+
$entityTypeId
89+
];
90+
}
91+
}
92+
93+
$io->table($tableHeader, array_values($tableRows));
94+
}
95+
}

0 commit comments

Comments
 (0)