public function UriNormalizer::denormalize in Tome 8
File
- modules/
tome_sync/ src/ Normalizer/ UriNormalizer.php, line 70
Class
- UriNormalizer
- Normalizer for Uri data.
Namespace
Drupal\tome_sync\NormalizerCode
public function denormalize($data, $type, $format = NULL, array $context = []) {
if (!empty($data) && strpos($data, 'entity:') === 0) {
$parts = explode('/', str_replace('entity:', '', $data));
if (count($parts) >= 2 && $this->entityTypeManager
->hasDefinition($parts[0]) && Uuid::isValid($parts[1])) {
if ($referenced_entity = $this->entityRepository
->loadEntityByUuid($parts[0], $parts[1])) {
$parts[1] = $referenced_entity
->id();
$data = 'entity:' . implode('/', $parts);
}
}
}
return $data;
}