You are here

public function ExportEntityWriter::addRootEntity in Content Synchronizer 8

Same name and namespace in other branches
  1. 8.2 src/Processors/ExportEntityWriter.php \Drupal\content_synchronizer\Processors\ExportEntityWriter::addRootEntity()
  2. 3.x src/Processors/ExportEntityWriter.php \Drupal\content_synchronizer\Processors\ExportEntityWriter::addRootEntity()

Add the entity to the exported root entities list.

Parameters

\Drupal\Core\Entity\Entity $entity: The root entity to add.

File

src/Processors/ExportEntityWriter.php, line 106

Class

ExportEntityWriter
Export entity writer.

Namespace

Drupal\content_synchronizer\Processors

Code

public function addRootEntity(Entity $entity) {
  $rootEntitiesFilePath = $this
    ->getDirPath() . '/' . self::ROOT_FILE_NAME . self::TYPE_EXTENSION;
  $rootEntities = $this
    ->getDataFromFile($rootEntitiesFilePath);
  if (!$rootEntities) {
    $rootEntities = [];
  }

  // Add entity data.
  $rootEntities[] = [
    self::FIELD_GID => $entity->contentSynchronizerGid,
    self::FIELD_ENTITY_TYPE_ID => $entity
      ->getEntityTypeId(),
    self::FIELD_ENTITY_ID => $entity
      ->id(),
    self::FIELD_LABEL => static::getEntityLabel($entity),
    self::FIELD_UUID => $entity
      ->uuid(),
  ];
  $this
    ->writeJson($rootEntities, $rootEntitiesFilePath);
}