public function PathAliasNormalizer::denormalize in Tome 8
Overrides EntityNormalizer::denormalize
File
- modules/
tome_sync/ src/ Normalizer/ PathAliasNormalizer.php, line 69
Class
- PathAliasNormalizer
- Normalizer for Path alias entities.
Namespace
Drupal\tome_sync\NormalizerCode
public function denormalize($data, $class, $format = NULL, array $context = []) {
/** @var \Drupal\path_alias\PathAliasInterface $entity */
$entity = parent::denormalize($data, $class, $format, $context);
foreach ([
'path',
'alias',
] as $key) {
if ($entity && !empty($entity
->get($key)->value)) {
$parts = explode('/', $entity
->get($key)->value);
if (count($parts) >= 3 && $this->entityTypeManager
->hasDefinition($parts[1]) && Uuid::isValid($parts[2])) {
if ($referenced_entity = $this->entityRepository
->loadEntityByUuid($parts[1], $parts[2])) {
$parts[2] = $referenced_entity
->id();
$entity
->set($key, implode('/', $parts));
}
}
}
}
return $entity;
}