httpClient = $http_client; } /** * {@inheritdoc} */ public function normalize($entity, $format = NULL, array $context = []) { $data = parent::normalize($entity, $format, $context); // Replace the file url with a full url for the file. $data['uri'][0]['value'] = $this->getEntityUri($entity); return $data; } /** * {@inheritdoc} */ public function denormalize($data, $class, $format = NULL, array $context = []) { $file_data = (string) $this->httpClient->get($data['uri'][0]['value'])->getBody(); $path = 'temporary://' . drupal_basename($data['uri'][0]['value']); $data['uri'] = file_unmanaged_save_data($file_data, $path); return $this->entityManager->getStorage('file')->create($data); } }