public function ContentEntityNormalizer::denormalize in Content Synchronization 8.2
Same name and namespace in other branches
- 3.0.x src/Normalizer/ContentEntityNormalizer.php \Drupal\content_sync\Normalizer\ContentEntityNormalizer::denormalize()
Overrides EntityNormalizer::denormalize
2 calls to ContentEntityNormalizer::denormalize()
- FileEntityNormalizer::denormalize in src/
Normalizer/ FileEntityNormalizer.php - Denormalizes data back into an object of the given class.
- UserEntityNormalizer::denormalize in src/
Normalizer/ UserEntityNormalizer.php - Denormalizes data back into an object of the given class.
2 methods override ContentEntityNormalizer::denormalize()
- FileEntityNormalizer::denormalize in src/
Normalizer/ FileEntityNormalizer.php - Denormalizes data back into an object of the given class.
- UserEntityNormalizer::denormalize in src/
Normalizer/ UserEntityNormalizer.php - Denormalizes data back into an object of the given class.
File
- src/
Normalizer/ ContentEntityNormalizer.php, line 70
Class
- ContentEntityNormalizer
- Adds the file URI to embedded file entities.
Namespace
Drupal\content_sync\NormalizerCode
public function denormalize($data, $class, $format = NULL, array $context = []) {
if (is_null($data)) {
return NULL;
}
$original_data = $data;
// Get the entity type ID while letting context override the $class param.
$entity_type_id = !empty($context['entity_type']) ? $context['entity_type'] : $this->entityTypeRepository
->getEntityTypeFromClass($class);
$bundle = FALSE;
/** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type_definition */
// Get the entity type definition.
$entity_type_definition = $this->entityTypeManager
->getDefinition($entity_type_id, FALSE);
if ($entity_type_definition
->hasKey('bundle')) {
$bundle_key = $entity_type_definition
->getKey('bundle');
// Get the base field definitions for this entity type.
$base_field_definitions = $this->entityFieldManager
->getBaseFieldDefinitions($entity_type_id);
// Get the ID key from the base field definition for the bundle key or
// default to 'value'.
$key_id = isset($base_field_definitions[$bundle_key]) ? $base_field_definitions[$bundle_key]
->getFieldStorageDefinition()
->getMainPropertyName() : 'value';
// Normalize the bundle if it is not explicitly set.
$bundle = isset($data[$bundle_key][0][$key_id]) ? $data[$bundle_key][0][$key_id] : (isset($data[$bundle_key]) ? $data[$bundle_key] : NULL);
}
// Decorate data before denormalizing it.
$this
->decorateDenormalization($data, $entity_type_id, $format, $context);
// Resolve references
$this
->fixReferences($data, $entity_type_id, $bundle);
// Remove invalid fields
$this
->cleanupData($data, $entity_type_id, $bundle);
// Data to Entity
$entity = parent::denormalize($data, $class, $format, $context);
// Decorate denormalized entity before retuning it.
$this
->decorateDenormalizedEntity($entity, $original_data, $format, $context);
return $entity;
}