public function AcquiaContenthubCommands::contenthubLocal in Acquia Content Hub 8
Prints the CDF from a local source (drupal site)
@command acquia:contenthub-local @aliases ach-lo,acquia-contenthub-local
Parameters
$entity_type: Entity type
$entity_id: Entity identifier or entity's UUID
File
- src/
Commands/ AcquiaContenthubCommands.php, line 43
Class
- AcquiaContenthubCommands
- A Drush commandfile.
Namespace
Drupal\acquia_contenthub\CommandsCode
public function contenthubLocal($entity_type, $entity_id) {
$entity_type_manager = \Drupal::entityTypeManager();
/** @var \Symfony\Component\Serializer\Serializer $serializer */
$serializer = \Drupal::service('serializer');
/** @var \Drupal\Core\Entity\EntityRepository $entity_repository */
$entity_repository = \Drupal::service('entity.repository');
if (empty($entity_type) || empty($entity_id)) {
throw new \Exception(dt("Missing required parameters: entity_type and entity_id (or entity's uuid)"));
}
elseif (!$entity_type_manager
->getDefinition($entity_type)) {
throw new \Exception(dt("Entity type @entity_type does not exist", [
'@entity_type' => $entity_type,
]));
}
else {
if (Uuid::isValid($entity_id)) {
$entity = $entity_repository
->loadEntityByUuid($entity_type, $entity_id);
}
else {
$entity = $entity_type_manager
->getStorage($entity_type)
->load($entity_id);
}
}
if (!$entity) {
$this
->output()
->writeln(dt("Entity having entity_type = @entity_type and entity_id = @entity_id does not exist.", [
'@entity_type' => $entity_type,
'@entity_id' => $entity_id,
]));
}
// If nothing else, return our object structure.
$output = $this
->handleNormalizedData($serializer
->normalize($entity, 'acquia_contenthub_cdf'));
$this
->output()
->writeln(print_r((array) $output['entities'][0], TRUE));
}