You are here

public function ContentHubCommonActions::getEntityCdf in Acquia Content Hub 8.2

Gets the CDF objects representation of an entity and its dependencies.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity from which to calculate dependencies and generate CDFObjects.

array $entities: (optional) The array of collected DependentEntityWrappers.

bool $return_minimal: Whether to dispatch the PUBLISH_ENTITIES event subscribers.

bool $calculate_dependencies: Whether to calculate dependencies on the entity.

Return value

\Acquia\ContentHubClient\CDF\CDFObject[] An array of CDFObjects.

Throws

\Exception

2 calls to ContentHubCommonActions::getEntityCdf()
ContentHubCommonActions::getEntityCdfFullKeyedByUuids in src/ContentHubCommonActions.php
Generates the CDF of an entity and all its dependencies keyed by UUIDs.
ContentHubCommonActions::getLocalCdfDocument in src/ContentHubCommonActions.php
Get a single merged CDF Document of entities and their dependencies.

File

src/ContentHubCommonActions.php, line 144

Class

ContentHubCommonActions
Common actions across the entirety of Content Hub.

Namespace

Drupal\acquia_contenthub

Code

public function getEntityCdf(EntityInterface $entity, array &$entities = [], bool $return_minimal = TRUE, bool $calculate_dependencies = TRUE) {
  $wrapper = new DependentEntityWrapper($entity);
  $stack = new DependencyStack();
  if ($calculate_dependencies) {
    $this->calculator
      ->calculateDependencies($wrapper, $stack);
  }

  /** @var \Drupal\depcalc\DependentEntityWrapper[] $entities */
  $entities = NestedArray::mergeDeep([
    $wrapper
      ->getUuid() => $wrapper,
  ], $stack
    ->getDependenciesByUuid(array_keys($wrapper
    ->getDependencies())));
  if ($return_minimal) {

    // Modify/Remove objects before publishing to ContentHub service.
    $event = new ContentHubPublishEntitiesEvent($entity
      ->uuid(), ...array_values($entities));
    $this->dispatcher
      ->dispatch(AcquiaContentHubEvents::PUBLISH_ENTITIES, $event);
    $entities = $event
      ->getDependencies();
  }
  return $this->serializer
    ->serializeEntities(...array_values($entities));
}