You are here

public function DefaultContentManager::exportContentWithReferences in Default Content 8

Exports a single entity and all its referenced entity.

Parameters

EntityInterface $entity: The entity type ID.

Return value

string[][] The serialized entities keyed by entity type and UUID.

Overrides DefaultContentManagerInterface::exportContentWithReferences

File

src/DefaultContentManager.php, line 178
Contains \Drupal\defaultcontent\DefaultContentManager. @todo remove all references to linkmanager?

Class

DefaultContentManager
A service for handling import of default content. @todo throw useful exceptions

Namespace

Drupal\defaultcontent

Code

public function exportContentWithReferences($entity_type_id, $entity_id) {
  $entity = $this->entityTypeManager
    ->getStorage($entity_type_id)
    ->load($entity_id);
  $entities = array_merge([
    $entity,
  ], $this
    ->getEntityReferencesRecursive($entity));
  $serialized_entities_per_type = [];

  //$this->linkManager->setLinkDomain(static::LINK_DOMAIN);

  // Serialize all entities and key them by entity TYPE and uuid.
  foreach ($entities as $entity) {
    $serialized_entities_per_type[$entity_type_id][$entity
      ->uuid()] = $this->serializer
      ->serialize($entity, 'hal_json', [
      'json_encode_options' => JSON_PRETTY_PRINT,
    ]);
  }

  //$this->linkManager->setLinkDomain(FALSE);
  return $serialized_entities_per_type;
}