public function ReplicationLogNormalizer::denormalize in Replication 8
Same name and namespace in other branches
- 8.2 src/Normalizer/ReplicationLogNormalizer.php \Drupal\replication\Normalizer\ReplicationLogNormalizer::denormalize()
@inheritDoc
File
- src/
Normalizer/ ReplicationLogNormalizer.php, line 62
Class
Namespace
Drupal\replication\NormalizerCode
public function denormalize($data, $class, $format = NULL, array $context = []) {
$data['_id'] = str_replace('_local/', '', $data['_id']);
$record = $this->uuidIndex
->get($data['_id']);
if (!empty($record['entity_type_id']) && !empty($record['entity_id'])) {
$storage = $this->entityTypeManager
->getStorage($record['entity_type_id']);
$entity = $storage
->load($record['entity_id']);
if ($entity instanceof ReplicationLogInterface) {
foreach ($data as $name => $value) {
$entity->{$name} = $value;
}
return $entity;
}
}
try {
$data['uuid'][0]['value'] = $data['_id'];
$entity = ReplicationLog::create($data);
return $entity;
} catch (\Exception $e) {
watchdog_exception('Replication', $e);
}
}