public function PathAliasNormalizer::normalize in Tome 8
Overrides ContentEntityNormalizer::normalize
File
- modules/
tome_sync/ src/ Normalizer/ PathAliasNormalizer.php, line 50
Class
- PathAliasNormalizer
- Normalizer for Path alias entities.
Namespace
Drupal\tome_sync\NormalizerCode
public function normalize($object, $format = NULL, array $context = []) {
$attributes = parent::normalize($object, $format, $context);
foreach ([
'path',
'alias',
] as $key) {
if (!empty($attributes[$key][0]['value'])) {
$parts = explode('/', $attributes[$key][0]['value']);
if (count($parts) >= 3 && $this->entityTypeManager
->hasDefinition($parts[1]) && is_numeric($parts[2])) {
if ($entity = $this->entityTypeManager
->getStorage($parts[1])
->load($parts[2])) {
$parts[2] = $entity
->uuid();
$attributes[$key][0]['value'] = implode('/', $parts);
}
}
}
}
return $attributes;
}