Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Debug / EntityCommand.php
diff --git a/vendor/drupal/console/src/Command/Debug/EntityCommand.php b/vendor/drupal/console/src/Command/Debug/EntityCommand.php
new file mode 100644 (file)
index 0000000..8965612
--- /dev/null
@@ -0,0 +1,90 @@
+<?php
+/**
+ * @file
+ * Contains \Drupal\Console\Command\Debug\EntityCommand.
+ */
+
+namespace Drupal\Console\Command\Debug;
+
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Drupal\Console\Core\Command\Command;
+use Drupal\Core\Entity\EntityTypeRepository;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
+
+class EntityCommand extends Command
+{
+    /**
+     * @var EntityTypeRepository
+     */
+    protected $entityTypeRepository;
+
+    /**
+     * @var EntityTypeManagerInterface
+     */
+    protected $entityTypeManager;
+
+    /**
+     * EntityCommand constructor.
+     *
+     * @param EntityTypeRepository       $entityTypeRepository
+     * @param EntityTypeManagerInterface $entityTypeManager
+     */
+    public function __construct(
+        EntityTypeRepository $entityTypeRepository,
+        EntityTypeManagerInterface $entityTypeManager
+    ) {
+        $this->entityTypeRepository = $entityTypeRepository;
+        $this->entityTypeManager = $entityTypeManager;
+        parent::__construct();
+    }
+    /**
+     * {@inheritdoc}
+     */
+    protected function configure()
+    {
+        $this
+            ->setName('debug:entity')
+            ->setDescription($this->trans('commands.debug.entity.description'))
+            ->addArgument(
+                'entity-type',
+                InputArgument::OPTIONAL,
+                $this->trans('commands.debug.entity.arguments.entity-type')
+            )->setAliases(['de']);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $entityType = $input->getArgument('entity-type');
+
+        $tableHeader = [
+            $this->trans('commands.debug.entity.table-headers.entity-name'),
+            $this->trans('commands.debug.entity.table-headers.entity-type')
+        ];
+        $tableRows = [];
+
+        $entityTypesLabels = $this->entityTypeRepository->getEntityTypeLabels(true);
+
+        if ($entityType) {
+            $entityTypes = [$entityType => $entityType];
+        } else {
+            $entityTypes = array_keys($entityTypesLabels);
+        }
+
+        foreach ($entityTypes as $entityTypeId) {
+            $entities = array_keys($entityTypesLabels[$entityTypeId]);
+            foreach ($entities as $entity) {
+                $tableRows[$entity] = [
+                    $entity,
+                    $entityTypeId
+                ];
+            }
+        }
+
+        $this->getIo()->table($tableHeader, array_values($tableRows));
+    }
+}