You are here

protected function EntityAliasTypeBase::bulkUpdate in Pathauto 8

Update the URL aliases for multiple entities.

Parameters

array $ids: An array of entity IDs.

array $options: An optional array of additional options.

Return value

int The number of updated URL aliases.

1 call to EntityAliasTypeBase::bulkUpdate()
EntityAliasTypeBase::batchUpdate in src/Plugin/pathauto/AliasType/EntityAliasTypeBase.php
Gets called to batch update all entries.

File

src/Plugin/pathauto/AliasType/EntityAliasTypeBase.php, line 266

Class

EntityAliasTypeBase
A pathauto alias type plugin for entities with canonical links.

Namespace

Drupal\pathauto\Plugin\pathauto\AliasType

Code

protected function bulkUpdate(array $ids, array $options = []) {
  $options += [
    'message' => FALSE,
  ];
  $updates = 0;
  $entities = $this->entityTypeManager
    ->getStorage($this
    ->getEntityTypeId())
    ->loadMultiple($ids);
  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);
      $result = \Drupal::service('pathauto.generator')
        ->updateEntityAlias($translated_entity, 'bulkupdate', $options);
      if ($result) {
        $updates++;
      }
    }
  }
  if (!empty($options['message'])) {
    $this->messenger
      ->addMessage($this->translationManager
      ->formatPlural(count($ids), 'Updated 1 %label URL alias.', 'Updated @count %label URL aliases.'), [
      '%label' => $this
        ->getLabel(),
    ]);
  }
  return $updates;
}