public function FileEntityNormalizer::denormalize in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/hal/src/Normalizer/FileEntityNormalizer.php \Drupal\hal\Normalizer\FileEntityNormalizer::denormalize()
Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize().
Parameters
array $data: Entity data to restore.
string $class: Unused, entity_create() is used to instantiate entity objects.
string $format: Format the given data was extracted from.
array $context: Options available to the denormalizer. Keys that can be used:
- request_method: if set to "patch" the denormalization will clear out all default values for entity fields before applying $data to the entity.
Throws
\Symfony\Component\Serializer\Exception\UnexpectedValueException
Overrides ContentEntityNormalizer::denormalize
File
- core/
modules/ hal/ src/ Normalizer/ FileEntityNormalizer.php, line 66 - Contains \Drupal\hal\Normalizer\FileEntityNormalizer.
Class
- FileEntityNormalizer
- Converts the Drupal entity object structure to a HAL array structure.
Namespace
Drupal\hal\NormalizerCode
public function denormalize($data, $class, $format = NULL, array $context = array()) {
$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);
}