/** * Tests the getEntityTypeLabels() method. * * @covers ::getEntityTypeLabels */ public function testGetEntityTypeLabels() { $apple = $this->prophesize(EntityTypeInterface::class); $apple->getLabel()->willReturn('Apple'); $apple->getBundleOf()->willReturn(NULL); $banana = $this->prophesize(EntityTypeInterface::class); $banana->getLabel()->willReturn('Banana'); $banana->getBundleOf()->willReturn(NULL); $this->setUpEntityTypeDefinitions(['apple' => $apple, 'banana' => $banana]); $expected = ['apple' => 'Apple', 'banana' => 'Banana']; $this->assertSame($expected, $this->entityTypeRepository->getEntityTypeLabels()); }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $entityDefinitionID = $input->getArgument('entity-definition-id'); $entityID = $input->getArgument('entity-id'); if (!$entityDefinitionID) { $entityTypes = $this->entityTypeRepository->getEntityTypeLabels(true); $entityType = $io->choice($this->trans('commands.entity.delete.questions.entity-type'), array_keys($entityTypes)); $entityDefinitionID = $io->choice($this->trans('commands.entity.delete.questions.entity-definition-id'), array_keys($entityTypes[$entityType])); $input->setArgument('entity-definition-id', $entityDefinitionID); } if (!$entityID) { $entityID = $io->ask($this->trans('commands.entity.delete.questions.entity-id')); $input->setArgument('entity-id', $entityID); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $entityType = $input->getArgument('entity-type'); $tableHeader = [$this->trans('commands.entity.debug.table-headers.entity-name'), $this->trans('commands.entity.debug.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]; } } $io->table($tableHeader, array_values($tableRows)); }