Created
February 28, 2019 15:51
-
-
Save rlnorthcutt/6caf472c3357b11fcac1a569a09da246 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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