You are here

public function EntityCdfSerializer::unserializeEntities in Acquia Content Hub 8.2

Unserializes a CDF into a list of Drupal entities.

@todo add more docs about the expected CDF format.

Parameters

\Acquia\ContentHubClient\CDFDocument $cdf: The CDF Document.

\Drupal\depcalc\DependencyStack $stack: The dependency stack object.

Throws

\Drupal\Core\Entity\EntityStorageException

\Exception

File

src/EntityCdfSerializer.php, line 144

Class

EntityCdfSerializer
Serialize an entity to a CDF format.

Namespace

Drupal\acquia_contenthub

Code

public function unserializeEntities(CDFDocument $cdf, DependencyStack $stack) {
  if (!$cdf
    ->hasEntities()) {
    throw new \Exception("Missing CDF Entities entry. Not a valid CDF.");
  }
  $cdf = $this
    ->preprocessCdf($cdf, $stack);

  // Install required modules.
  $this
    ->handleModules($cdf, $stack);

  // Organize the entities into a dependency chain.
  // Use a while loop to prevent memory expansion due to recursion.
  while (!$stack
    ->hasDependencies(array_keys($cdf
    ->getEntities()))) {

    // @todo add tracking to break out of the while loop when dependencies cannot be further processed.
    $count = count($stack
      ->getDependencies());
    $this
      ->processCdf($cdf, $stack);
    $this
      ->handleImportFailure($count, $cdf, $stack);
  }
  $this->tracker
    ->cleanUp();
}