function ContentExportCommand::execute
File
-
core/
lib/ Drupal/ Core/ DefaultContent/ ContentExportCommand.php, line 45
Class
- ContentExportCommand
- Exports a single content entity in YAML format.
Namespace
Drupal\Core\DefaultContentCode
protected function execute(InputInterface $input, OutputInterface $output) : int {
$io = new SymfonyStyle($input, $output);
$container = $this->boot()
->getContainer();
$entity_type_id = $input->getArgument('entity_type_id');
$entity_id = $input->getArgument('entity_id');
$entity_type_manager = $container->get(EntityTypeManagerInterface::class);
if (!$entity_type_manager->hasDefinition($entity_type_id)) {
$io->error("The entity type \"{$entity_type_id}\" does not exist.");
return 1;
}
if (!$entity_type_manager->getDefinition($entity_type_id)
->entityClassImplements(ContentEntityInterface::class)) {
$io->error("{$entity_type_id} is not a content entity type.");
return 1;
}
$entity = $entity_type_manager->getStorage($entity_type_id)
->load($entity_id);
if (!$entity instanceof ContentEntityInterface) {
$io->error("{$entity_type_id} {$entity_id} does not exist.");
return 1;
}
$data = $container->get(Exporter::class)
->export($entity);
$io->write(Yaml::encode($data));
return 0;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.