You are here

private function ImportEntityManager::updateHostEntity in Acquia Content Hub 8

Updates the reference in the host entity to point to the dependent entity.

In cases of dependent entities (paragraphs and field collections), we need to update the reference in the host entity to point to the dependent entity after the dependent entity has been saved.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: A Drupal entity interface.

1 call to ImportEntityManager::updateHostEntity()
ImportEntityManager::importRemoteEntityNoDependencies in src/ImportEntityManager.php
Saves an Entity without taking care of dependencies.

File

src/ImportEntityManager.php, line 780

Class

ImportEntityManager
Provides a service for managing imported entities' actions.

Namespace

Drupal\acquia_contenthub

Code

private function updateHostEntity(EntityInterface $entity) {
  switch ($entity
    ->getEntityTypeId()) {
    case 'paragraph':
      $host_entity = $entity
        ->getParentEntity();

      // Assuming single parenthood.
      $field_paragraph = $entity
        ->get('parent_field_name')
        ->getString();
      $host_entity->{$field_paragraph}
        ->appendItem($entity);

      // Add synchronization flag.
      $host_entity->__contenthub_entity_syncing = TRUE;

      // Save the host entity.
      $host_entity
        ->save();

      // Remove synchronization flag.
      unset($host_entity->__contenthub_entity_syncing);
      break;
  }
}