public function ExportEntityWriter::write in Content Synchronizer 3.x
Same name and namespace in other branches
- 8.2 src/Processors/ExportEntityWriter.php \Drupal\content_synchronizer\Processors\ExportEntityWriter::write()
- 8 src/Processors/ExportEntityWriter.php \Drupal\content_synchronizer\Processors\ExportEntityWriter::write()
Write the document to export.
Parameters
\Drupal\Core\Entity\EntityInterface $entityToExport: The entity to export.
array $dataToExport: The data to export.
File
- src/Processors/ ExportEntityWriter.php, line 90 
Class
- ExportEntityWriter
- Export entity writer.
Namespace
Drupal\content_synchronizer\ProcessorsCode
public function write(EntityInterface $entityToExport, array $dataToExport) {
  if (array_key_exists('gid', $dataToExport) && ($gid = $dataToExport['gid'])) {
    // Get the previous exported entities :
    if ($allExportedData = $this
      ->getExportedData($entityToExport)) {
      // If the current entity has already been exported, the writer don't
      // do anything.
      if (array_key_exists($gid, $allExportedData)) {
        return;
      }
    }
    else {
      $allExportedData = [];
    }
    // Add the current entity to export to the already exported data.
    $allExportedData[$gid] = $dataToExport;
    // Write files :
    $this
      ->writeJson($allExportedData, $this
      ->getExpotedDataTypeFilePath($entityToExport));
  }
}