You are here

protected function Importer::decodeFile in Default Content Deploy 8

Prepare file to import.

Parameters

$file:

Return value

$this

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Exception

1 call to Importer::decodeFile()
Importer::prepareForImport in src/Importer.php
Import data from JSON and create new entities, or update existing.

File

src/Importer.php, line 363

Class

Importer
A service for handling import of default content.

Namespace

Drupal\default_content_deploy

Code

protected function decodeFile($file) {

  // Check that this file has not been decoded already.
  if (array_key_exists($file->name, $this->discoveredReferences)) {
    return $this;
  }

  // Get parsed data.
  $parsed_data = file_get_contents($file->uri);

  // Decode.
  $decode = $this->serializer
    ->decode($parsed_data, 'hal_json');
  $references = $this
    ->getReferences($decode);

  // Record that we have checked references of current file.
  $this->discoveredReferences[$file->name] = $file;
  if ($references) {
    foreach ($references as $reference) {
      $this
        ->decodeFile($reference);
    }
  }

  // Prepare data for import.
  $link = $decode['_links']['type']['href'];
  $data_to_import = [
    'data' => $decode,
    'entity_type_id' => $this
      ->getEntityTypeByLink($link),
    'references' => $references,
  ];
  $this
    ->preAddToImport($data_to_import);
  $this
    ->addToImport($data_to_import);
  return $this;
}