private function Exporter::getSerializedContentWithReferences in Default Content Deploy 8
Exports a single entity and all its referenced entity.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity:
Return value
array
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
1 call to Exporter::getSerializedContentWithReferences()
- Exporter::prepareToExportWithReference in src/
Exporter.php - Prepare content with reference to export.
File
- src/
Exporter.php, line 539
Class
- Exporter
- A service for handling export of default content.
Namespace
Drupal\default_content_deployCode
private function getSerializedContentWithReferences(ContentEntityInterface $entity) {
$indexed_dependencies = [
$entity
->uuid() => $entity,
];
$entities = $this
->getEntityReferencesRecursive($entity, 0, $indexed_dependencies);
$host = $this->deployManager
->getCurrentHost();
$serialized_entities = [];
$this->linkManager
->setLinkDomain($host);
if (PHP_SAPI === 'cli') {
$root_user = $this->entityTypeManager
->getStorage('user')
->load(1);
$this->accountSwitcher
->switchTo($root_user);
}
// Serialize all entities and key them by entity TYPE and uuid.
foreach ($entities as $entity) {
$serialize = $this->serializer
->serialize($entity, 'hal_json', [
'json_encode_options' => JSON_PRETTY_PRINT,
]);
$serialized_entities[$entity
->getEntityTypeId()][$entity
->uuid()] = $serialize;
}
// Reset the link domain and the current user, if needed.
$this->linkManager
->setLinkDomain(FALSE);
if (PHP_SAPI === 'cli') {
$this->accountSwitcher
->switchBack();
}
return $serialized_entities;
}