You are here

public function FileEntityNormalizer::denormalize in Replication 8

Same name and namespace in other branches
  1. 8.2 src/Normalizer/FileEntityNormalizer.php \Drupal\replication\Normalizer\FileEntityNormalizer::denormalize()

Overrides ContentEntityNormalizer::denormalize

File

src/Normalizer/FileEntityNormalizer.php, line 84

Class

FileEntityNormalizer

Namespace

Drupal\replication\Normalizer

Code

public function denormalize($data, $class, $format = NULL, array $context = []) {
  $file = NULL;
  if (!empty($data['@attachment']['uuid'])) {
    $workspace = isset($context['workspace']) ? $context['workspace'] : NULL;

    /** @var FileInterface $file */
    if ($file = $this->processFileAttachment
      ->process($data['@attachment'], 'base64_stream', $workspace)) {

      // Update the data, because file name could change.
      $language_code = $file
        ->language()
        ->getId();
      $data[$language_code]['filename'][0]['value'] = $file
        ->get('filename')->value;
      $data[$language_code]['uri'][0]['value'] = $file
        ->get('uri')->value;
    }
    unset($data['@attachment']);
  }
  return parent::denormalize($data, $class, $format, $context);
}