You are here

public static function PathautoState::bulkDelete in Pathauto 8

Deletes the URL aliases for multiple entities of the same type.

Parameters

string $entity_type_id: The entity type ID of entities being deleted.

int[] $pids_by_id: A list of path IDs keyed by entity ID.

2 calls to PathautoState::bulkDelete()
EntityAliasTypeBase::batchDelete in src/Plugin/pathauto/AliasType/EntityAliasTypeBase.php
Gets called to batch delete all aliases created by pathauto.
EntityAliasTypeBase::bulkDelete in src/Plugin/pathauto/AliasType/EntityAliasTypeBase.php
Deletes the URL aliases for multiple entities.

File

src/PathautoState.php, line 133

Class

PathautoState
A property that stores in keyvalue whether an entity should receive an alias.

Namespace

Drupal\pathauto

Code

public static function bulkDelete($entity_type_id, array $pids_by_id) {
  foreach ($pids_by_id as $id => $pid) {

    // Some key-values store entries have computed keys.
    $key = static::getPathautoStateKey($id);
    if ($key !== $id) {
      $pids_by_id[$key] = $pid;
      unset($pids_by_id[$id]);
    }
  }
  $states = \Drupal::keyValue("pathauto_state.{$entity_type_id}")
    ->getMultiple(array_keys($pids_by_id));
  $pids = [];
  foreach ($pids_by_id as $id => $pid) {

    // Only delete aliases that were created by this module.
    if (isset($states[$id]) && $states[$id] == PathautoState::CREATE) {
      $pids[] = $pid;
    }
  }
  \Drupal::service('pathauto.alias_storage_helper')
    ->deleteMultiple($pids);
}