public function AcquiaContentHubEntityCommands::contenthubEntity in Acquia Content Hub 8.2
Retrieves an Entity from a local source or contenthub.
@option decode Decodes the metadata 'data' element to make it easier to understand the content of each CDF entity stored in Content Hub.
@command acquia:contenthub-entity @aliases ach-ent
Parameters
string $op: The operation being performed.
string $uuid: Entity identifier or entity's UUID.
string $entity_type: The entity type in case of local retrieval.
array $options: An associative array of options whose values come from cli, aliases, config, etc.
Throws
\Exception
2 calls to AcquiaContentHubEntityCommands::contenthubEntity()
- AcquiaContentHubEntityCommands::contenthubLocal in src/
Commands/ AcquiaContentHubEntityCommands.php - Prints the CDF from a local source (drupal site)
- AcquiaContentHubEntityCommands::contenthubRemote in src/
Commands/ AcquiaContentHubEntityCommands.php - Prints the CDF from a remote source (Content Hub)
File
- src/
Commands/ AcquiaContentHubEntityCommands.php, line 67
Class
- AcquiaContentHubEntityCommands
- Drush commands for interacting with Acquia Content Hub entities.
Namespace
Drupal\acquia_contenthub\CommandsCode
public function contenthubEntity($op, $uuid, $entity_type = NULL, array $options = [
'decode' => NULL,
]) {
if (empty($uuid)) {
throw new \Exception("Please supply the uuid of the entity you want to retrieve.");
}
switch ($op) {
case 'local':
if (empty($entity_type)) {
throw new \Exception(dt("Entity_type is required for local entities"));
}
$repository = \Drupal::service('entity.repository');
$entity = $repository
->loadEntityByUuid($entity_type, $uuid);
$entities = [];
$objects = $this->commonActions
->getEntityCdf($entity, $entities, FALSE, TRUE);
$data = [];
foreach ($objects as $object) {
$data[$object
->getUuid()] = $object
->toArray();
// Decode the base64 'data' element in 'metadata'.
if ($options['decode']) {
$this
->decodeEntityArrayMetadata($data[$object
->getUuid()]);
}
}
$json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$this
->output()
->writeln($json);
break;
case 'remote':
$entity = $this->commonActions
->getRemoteEntity($uuid);
$entity_array = $entity
->toArray();
// Decode the base64 'data' element in 'metadata'.
if ($options['decode']) {
$this
->decodeEntityArrayMetadata($entity_array);
}
elseif (!$entity instanceof CDFObjectInterface) {
return;
}
$json = json_encode($entity_array, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$this
->output()
->writeln($json);
break;
default:
// Invalid operation.
throw new \Exception(dt('The op "@op" is invalid', [
'@op' => $op,
]));
}
}