public function NodeEntityNormalizer::normalize in Default Content Extras 8
Overrides ContentEntityNormalizer::normalize
File
- src/
Normalizer/ NodeEntityNormalizer.php, line 55
Class
- NodeEntityNormalizer
- Defines a class for normalizing nodes.
Namespace
Drupal\default_content_extra\NormalizerCode
public function normalize($entity, $format = NULL, array $context = array()) {
$normalized = parent::normalize($entity, $format, $context);
if (!$entity
->isNew() && $this->config
->get('path_alias')) {
$nid = $entity
->id();
$path = Url::fromRoute('entity.node.canonical', [
'node' => $nid,
])
->toString();
// If it's not a system path export it.
if ($path != "/node/{$nid}") {
$normalized['path'] = [
'alias' => $path,
];
}
}
return $normalized;
}