Skip to content

Instantly share code, notes, and snippets.

@rlnorthcutt
Created February 28, 2019 15:51
Show Gist options
  • Save rlnorthcutt/6caf472c3357b11fcac1a569a09da246 to your computer and use it in GitHub Desktop.
Save rlnorthcutt/6caf472c3357b11fcac1a569a09da246 to your computer and use it in GitHub Desktop.
<?php
use Drupal\Component\Utility\NestedArray;
if (empty($extra[0])) {
throw new \Exception("Please supply the id of the node you want to export to CDF.");
}
$node = \Drupal::entityTypeManager()->getStorage('node')->load($extra[0]);
$wrapper = new \Drupal\depcalc\DependentEntityWrapper($node);
$stack = new \Drupal\depcalc\DependencyStack();
/** @var \Drupal\depcalc\DependencyCalculator $calculator */
$calculator = \Drupal::service('entity.dependency.calculator');
$dependencies = $calculator->calculateDependencies($wrapper, $stack);
$entities = NestedArray::mergeDeep([$wrapper->getUuid() => $wrapper], $stack->getDependenciesByUuid(array_keys($wrapper->getDependencies())));
/** @var \Drupal\acquia_contenthub\EntityCDFSerializer $serializer */
$serializer = \Drupal::service('entity.cdf.serializer');
/** @var \Acquia\ContentHubClient\CDFObject $data */
$data = $serializer->serializeEntities(...array_values($entities));
$document = new \Acquia\ContentHubClient\CDFDocument(...$data);
print $document->toString();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment