You are here

public function ExportEntityWriter::addRootEntity in Content Synchronizer 3.x

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

Add the entity to the exported root entities list.

Parameters

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

File

src/Processors/ExportEntityWriter.php, line 135

Class

ExportEntityWriter
Export entity writer.

Namespace

Drupal\content_synchronizer\Processors

Code

public function addRootEntity(EntityInterface $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);
}