You are here

protected function EntityCdfSerializer::processCdf in Acquia Content Hub 8.2

Processes incoming CDF.

Parameters

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

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

Throws

\Drupal\Core\Entity\EntityStorageException

1 call to EntityCdfSerializer::processCdf()
EntityCdfSerializer::unserializeEntities in src/EntityCdfSerializer.php
Unserializes a CDF into a list of Drupal entities.

File

src/EntityCdfSerializer.php, line 326

Class

EntityCdfSerializer
Serialize an entity to a CDF format.

Namespace

Drupal\acquia_contenthub

Code

protected function processCdf(CDFDocument $cdf, DependencyStack $stack) {
  foreach ($this
    ->getUnprocessedDependencies($cdf, $stack) as $entity_data) {
    if (!$this
      ->entityIsProcessable($entity_data, $stack)) {
      continue;
    }
    $uuid = $entity_data
      ->getUuid();
    $entity = $this
      ->getEntityFromCdf($entity_data, $stack);
    if (!$entity) {

      // Remove CDF Entities that were processable but didn't resolve into
      // an entity.
      $cdf
        ->removeCdfEntity($uuid);
      continue;
    }
    $pre_entity_save_event = new PreEntitySaveEvent($entity, $stack, $entity_data);
    $this->dispatcher
      ->dispatch(AcquiaContentHubEvents::PRE_ENTITY_SAVE, $pre_entity_save_event);
    $entity = $pre_entity_save_event
      ->getEntity();

    // Added to avoid creating new revisions with stubbed data.
    // See \Drupal\content_moderation\Entity\Handler\ModerationHandler.
    if ($entity instanceof SynchronizableInterface) {
      $entity
        ->setSyncing(TRUE);
    }
    $entity
      ->save();
    $this
      ->addToStack($entity, $uuid, $stack);
    $this
      ->dispatchImportEvent($entity, $entity_data);
  }
}