You are here

public function Alias::decorateNormalization in Content Synchronization 3.0.x

Same name and namespace in other branches
  1. 8.2 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\SyncNormalizerDecorator

Code

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,
          ],
        ];
      }
    }
  }
}