You are here

protected function JsonWriterTrait::writeJson in Content Synchronizer 3.x

Same name and namespace in other branches
  1. 8.2 src/Base/JsonWriterTrait.php \Drupal\content_synchronizer\Base\JsonWriterTrait::writeJson()
  2. 8 src/Base/JsonWriterTrait.php \Drupal\content_synchronizer\Base\JsonWriterTrait::writeJson()

Save json in the destination file.

3 calls to JsonWriterTrait::writeJson()
ExportEntityWriter::addRootEntity in src/Processors/ExportEntityWriter.php
Add the entity to the exported root entities list.
ExportEntityWriter::write in src/Processors/ExportEntityWriter.php
Write the document to export.
ImportEntity::setGidStatus in src/Entity/ImportEntity.php
Set the status of the entity.

File

src/Base/JsonWriterTrait.php, line 23

Class

JsonWriterTrait
Json writer tool.

Namespace

Drupal\content_synchronizer\Base

Code

protected function writeJson($data, $destination) {

  // Create dir :
  $dir = explode('/', $destination);
  array_pop($dir);
  $dir = implode('/', $dir);
  $this
    ->createDirectory($dir);
  $this
    ->fileSystem()
    ->prepareDirectory($dir, FileSystem::CHMOD_DIRECTORY);
  $uri = $this
    ->fileSystem()
    ->saveData(json_encode($data), $destination, FileSystem::EXISTS_REPLACE);
  File::create([
    'uri' => $uri,
    'status' => FILE_STATUS_PERMANENT,
  ])
    ->save();
}