public function Alias::decorateNormalization in Content Synchronization 8.2
Same name and namespace in other branches
- 3.0.x src/Plugin/SyncNormalizerDecorator/Alias.php \Drupal\content_sync\Plugin\SyncNormalizerDecorator\Alias::decorateNormalization()
Parameters
array $normalized_entity:
\Drupal\Core\Entity\ContentEntityInterface $entity:
$format:
array $context:
Overrides SyncNormalizerDecoratorBase::decorateNormalization
File
- src/
Plugin/ SyncNormalizerDecorator/ Alias.php, line 55
Class
- Alias
- Provides a decorator for setting the alias to entity.
Namespace
Drupal\content_sync\Plugin\SyncNormalizerDecoratorCode
public function decorateNormalization(array &$normalized_entity, ContentEntityInterface $entity, $format, array $context = []) {
if ($entity
->hasLinkTemplate('canonical')) {
$url = $entity
->toUrl();
if (!empty($url)) {
$system_path = '/' . $url
->getInternalPath();
$langcode = $entity
->language()
->getId();
$path_alias = $this->aliasManager
->getAliasByPath($system_path, $langcode);
if (!empty($path_alias) && $path_alias != $system_path) {
$normalized_entity['path'] = [
[
'alias' => $path_alias,
],
];
}
}
}
}