You are here

public function ImportEntity::getRootsEntities in Content Synchronizer 8

Same name and namespace in other branches
  1. 8.2 src/Entity/ImportEntity.php \Drupal\content_synchronizer\Entity\ImportEntity::getRootsEntities()
  2. 3.x src/Entity/ImportEntity.php \Drupal\content_synchronizer\Entity\ImportEntity::getRootsEntities()

Return the entities to import list.

Return value

array The list of roots entities.

1 call to ImportEntity::getRootsEntities()
ImportEntity::isRootEntity in src/Entity/ImportEntity.php
Check if the entity is a root entity.

File

src/Entity/ImportEntity.php, line 302

Class

ImportEntity
Defines the Import entity.

Namespace

Drupal\content_synchronizer\Entity

Code

public function getRootsEntities() {
  if (is_null($this->rootEntities)) {
    if (!file_exists($this
      ->getArchiveFilesPath())) {
      $this
        ->unzipArchive();
    }
    $this->rootEntities = $this
      ->getDataFromFile($this
      ->getArchiveFilesPath() . '/' . ExportEntityWriter::ROOT_FILE_NAME . ExportEntityWriter::TYPE_EXTENSION);
    foreach ($this->rootEntities as &$entity) {
      $existingEntity = $this->globalReferenceManager
        ->getExistingEntityByGidAndUuid($entity[ExportEntityWriter::FIELD_GID], $entity[ExportEntityWriter::FIELD_UUID]);
      if ($existingEntity) {
        $entity['status'] = 'update';
        $entity['edit_url'] = Url::fromRoute('entity.' . $existingEntity
          ->getEntityTypeId() . '.edit_form', [
          $existingEntity
            ->getEntityTypeId() => $existingEntity
            ->id(),
        ]);
        $entity['view_url'] = $existingEntity
          ->toUrl();
      }
      else {
        $entity['status'] = 'create';
      }
    }
  }
  return $this->rootEntities;
}