You are here

private function ReplicationFinished::updateEntitiesAlias in Workspace 8

1 call to ReplicationFinished::updateEntitiesAlias()
ReplicationFinished::onInternalReplicationFinished in src/EventSubscriber/ReplicationFinished.php
Listener for replication finished.

File

src/EventSubscriber/ReplicationFinished.php, line 115

Class

ReplicationFinished
Class ReplicationFinished.

Namespace

Drupal\workspace\EventSubscriber

Code

private function updateEntitiesAlias($entity_type_id, $limit = 50) {
  $storage = $this->entityTypeManager
    ->getStorage($entity_type_id);
  if ($storage instanceof ContentEntityStorageInterface) {
    $query = $storage
      ->getQuery()
      ->condition('_deleted', 0);
    if ($entity_type_id === 'node') {
      $query
        ->condition('status', 1);
    }
    $ids = $query
      ->execute();
    foreach (array_chunk($ids, $limit) as $ids_subset) {
      $entities = $storage
        ->loadMultiple($ids_subset);
      foreach ($entities as $entity) {

        // Update aliases for the entity's default language
        // and its translations.
        foreach ($entity
          ->getTranslationLanguages() as $langcode => $language) {
          $translated_entity = $entity
            ->getTranslation($langcode);
          if ($this->pathAutoGenerator
            ->updateEntityAlias($translated_entity, 'insert')) {
            \Drupal::logger('replication')
              ->info('Entity %entity_type(%id) alias update', [
              '%entity_type' => $entity_type_id,
              '%id' => $entity
                ->id(),
            ]);
          }
        }
      }
    }
  }
}