You are here

public function Exporter::getSerializedContent in Default Content Deploy 8

Exports a single entity as importContent expects it.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity:

Return value

string

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

2 calls to Exporter::getSerializedContent()
Exporter::prepareToExport in src/Exporter.php
Prepare content to export.
Exporter::prepareToExportAllContent in src/Exporter.php
Prepare all content on the site to export.

File

src/Exporter.php, line 511

Class

Exporter
A service for handling export of default content.

Namespace

Drupal\default_content_deploy

Code

public function getSerializedContent(ContentEntityInterface $entity) {
  if (PHP_SAPI === 'cli') {
    $root_user = $this->entityTypeManager
      ->getStorage('user')
      ->load(1);
    $this->accountSwitcher
      ->switchTo($root_user);
  }
  $host = $this->deployManager
    ->getCurrentHost();
  $this->linkManager
    ->setLinkDomain($host);
  $content = $this->serializer
    ->serialize($entity, 'hal_json', [
    'json_encode_options' => JSON_PRETTY_PRINT,
  ]);
  $this->linkManager
    ->setLinkDomain(FALSE);
  if (PHP_SAPI === 'cli') {
    $this->accountSwitcher
      ->switchBack();
  }
  return $content;
}