You are here

public function DefaultContentManager::exportContentWithMenuLinks in Default Content 8

Exports a single entity as importContent expects it.

Parameters

EntityInterface $entity: The entity type ID.

Return value

string The rendered export as hal.

Overrides DefaultContentManagerInterface::exportContentWithMenuLinks

File

src/DefaultContentManager.php, line 153
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 exportContentWithMenuLinks($entity_type_id, $entity_id) {
  $entity = $this->entityTypeManager
    ->getStorage($entity_type_id)
    ->load($entity_id);

  //$this->linkManager->setLinkDomain(static::LINK_DOMAIN);
  $serialized = $this->serializer
    ->serialize($entity, 'hal_json', [
    'json_encode_options' => JSON_PRETTY_PRINT,
  ]);
  $serialized_entities_per_type[$entity_type_id][$entity
    ->uuid()] = $serialized;

  // Reset link domain.

  //$this->linkManager->setLinkDomain(FALSE);

  //now add the menu links
  if ($item = $this
    ->getMenuLink($entity)) {
    $serialized_entities_per_type['menu_link_content'][$entity
      ->uuid()] = $item;
  }
  return $serialized_entities_per_type;
}