class AttachmentNormalizer in Replication 8
Same name and namespace in other branches
- 8.2 src/Normalizer/AttachmentNormalizer.php \Drupal\replication\Normalizer\AttachmentNormalizer
Hierarchy
- class \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\SerializerAwareInterface, CacheableNormalizerInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
- class \Drupal\replication\Normalizer\ContentEntityNormalizer implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface uses FieldableEntityNormalizerTrait
- class \Drupal\replication\Normalizer\AttachmentNormalizer implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
- class \Drupal\replication\Normalizer\ContentEntityNormalizer implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface uses FieldableEntityNormalizerTrait
Expanded class hierarchy of AttachmentNormalizer
1 string reference to 'AttachmentNormalizer'
1 service uses AttachmentNormalizer
File
- src/
Normalizer/ AttachmentNormalizer.php, line 9
Namespace
Drupal\replication\NormalizerView source
class AttachmentNormalizer extends ContentEntityNormalizer implements DenormalizerInterface {
/**
* @var string[]
*/
protected $supportedInterfaceOrClass = [
'\\Drupal\\file\\FileInterface',
];
/**
* @var string[]
*/
protected $format = [
'stream',
'base64_stream',
];
/**
* {@inheritdoc}
*/
public function normalize($data, $format = NULL, array $context = []) {
// If the 'new_revision_id' context is TRUE then normalize file entity as a
// content entity not stream.
if (!empty($context['new_revision_id'])) {
return parent::normalize($data, $format, $context);
}
/** @var \Drupal\file\FileInterface $data */
$stream = fopen($data
->getFileUri(), 'r');
return $stream;
}
/**
* {@inheritdoc}
*/
public function denormalize($data, $class, $format = NULL, array $context = []) {
$meta_data = is_resource($data) ? stream_get_meta_data($data) : NULL;
// @todo {@link https://www.drupal.org/node/2599926 Use $class to instantiate the entity.}
$file_data = [];
if (isset($meta_data['uri'])) {
$file_data['uri'] = $meta_data['uri'];
}
elseif (isset($context['uri'])) {
$file_data['uri'] = $context['uri'];
}
$file_info_keys = [
'uuid',
'status',
'uid',
'workspace',
];
foreach ($file_info_keys as $key) {
if (isset($context[$key])) {
$file_data[$key] = $context[$key];
}
}
if (isset($context['uuid'])) {
$workspace = isset($context['workspace']) ? $context['workspace'] : NULL;
/** @var UuidIndexInterface $uuid_index */
$uuid_index = $this->indexFactory
->get('multiversion.entity_index.uuid', $workspace);
$entity_info = $uuid_index
->get($context['uuid']);
if (!empty($entity_info)) {
/** @var FileInterface $file */
$file = $this->entityManager
->getStorage($entity_info['entity_type_id'])
->load($entity_info['entity_id']);
if (!empty($file)) {
foreach ($file_data as $key => $data) {
$file->{$key} = $data;
}
return $file;
}
}
}
return $this->entityManager
->getStorage('file')
->create($file_data);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AttachmentNormalizer:: |
protected | property |
Overrides ContentEntityNormalizer:: |
|
AttachmentNormalizer:: |
protected | property |
Overrides ContentEntityNormalizer:: |
|
AttachmentNormalizer:: |
public | function |
Denormalizes data back into an object of the given class. Overrides ContentEntityNormalizer:: |
|
AttachmentNormalizer:: |
public | function |
Normalizes an object into a set of arrays/scalars. Overrides ContentEntityNormalizer:: |
|
CacheableNormalizerInterface:: |
constant | Name of key for bubbling cacheability metadata via serialization context. | ||
ContentEntityNormalizer:: |
protected | property | ||
ContentEntityNormalizer:: |
protected | property | ||
ContentEntityNormalizer:: |
protected | property | ||
ContentEntityNormalizer:: |
private | property | ||
ContentEntityNormalizer:: |
protected | property | ||
ContentEntityNormalizer:: |
protected | property | ||
ContentEntityNormalizer:: |
private | function | Handles entity creation for fieldable and non-fieldable entities. | |
ContentEntityNormalizer:: |
protected | function | ||
ContentEntityNormalizer:: |
private | function | ||
ContentEntityNormalizer:: |
public | function | 1 | |
FieldableEntityNormalizerTrait:: |
protected | property | The entity field manager. | |
FieldableEntityNormalizerTrait:: |
protected | property | The entity type manager. | 1 |
FieldableEntityNormalizerTrait:: |
protected | property | The entity type repository. | |
FieldableEntityNormalizerTrait:: |
protected | function | Build the field item value using the incoming data. | 7 |
FieldableEntityNormalizerTrait:: |
protected | function | Denormalizes entity data by denormalizing each field individually. | |
FieldableEntityNormalizerTrait:: |
protected | function | Determines the entity type ID to denormalize as. | |
FieldableEntityNormalizerTrait:: |
protected | function | Denormalizes the bundle property so entity creation can use it. | |
FieldableEntityNormalizerTrait:: |
protected | function | Returns the entity field manager. | |
FieldableEntityNormalizerTrait:: |
protected | function | Gets the entity type definition. | |
FieldableEntityNormalizerTrait:: |
protected | function | Returns the entity type manager. | |
FieldableEntityNormalizerTrait:: |
protected | function | Returns the entity type repository. | |
NormalizerBase:: |
protected | function | Adds cacheability if applicable. | |
NormalizerBase:: |
protected | function | Checks if the provided format is supported by this normalizer. | 2 |
NormalizerBase:: |
public | function | Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() | 1 |
NormalizerBase:: |
public | function | Checks whether the given class is supported for normalization by this normalizer. | 1 |