You are here

private function ContentEntityCdfNormalizer::processPassAlias in Acquia Content Hub 8

Processes path alias entities.

For imported entity replaces 'path' value by the local path. Removes some extra attributes like: title, path_uuid, target_entity_type.

Parameters

string $entity_type: Type of entity to process.

\Acquia\ContentHubClient\Entity $contenthub_entity: Content Hub entity for processing.

array $langcodes: Langcodes for processing.

Throws

\Drupal\Core\Entity\EntityMalformedException

\Drupal\Core\Entity\EntityStorageException

1 call to ContentEntityCdfNormalizer::processPassAlias()
ContentEntityCdfNormalizer::denormalize in src/Normalizer/ContentEntityCdfNormalizer.php
Denormalizes data back into an object of the given class.

File

src/Normalizer/ContentEntityCdfNormalizer.php, line 1547

Class

ContentEntityCdfNormalizer
Converts the Drupal entity object to a Acquia Content Hub CDF array.

Namespace

Drupal\acquia_contenthub\Normalizer

Code

private function processPassAlias(string $entity_type, ContentHubEntity $contenthub_entity, array $langcodes) {
  if ($entity_type !== 'path_alias') {
    return;
  }
  $path_uuid = $contenthub_entity
    ->getAttribute('path_uuid');
  $target_entity_type = $contenthub_entity
    ->getAttribute('target_entity_type');
  $path_attribute = new Attribute(Attribute::TYPE_ARRAY_STRING);
  foreach ($langcodes as $langcode) {
    if (empty($path_uuid['value'][$langcode])) {
      continue;
    }
    $local_target_entity = $this->entityRepository
      ->loadEntityByUuid($target_entity_type['value'][$langcode], $path_uuid['value'][$langcode]);
    if (empty($local_target_entity)) {
      continue;
    }
    $local_path = '/' . ltrim($local_target_entity
      ->toUrl()
      ->getInternalPath(), '/');
    $path_attribute
      ->setValue($local_path, $langcode);
  }

  // Replace path attribute by local path.
  $attributes = $contenthub_entity
    ->getAttributes();
  $attributes['path'] = (array) $path_attribute;
  $contenthub_entity
    ->setAttributes($attributes);
  $contenthub_entity
    ->removeAttribute('title');
  $contenthub_entity
    ->removeAttribute('path_uuid');
  $contenthub_entity
    ->removeAttribute('target_entity_type');
}