You are here

public static function PathautoState::getPathautoStateKey in Pathauto 8

Gets the key-value store entry key for 'pathauto_state.*' collections.

Normally we want to use the entity ID as key for 'pathauto_state.*' collection entries. But some entity types may use string IDs. When such IDs are exceeding 128 characters, which is the limit for the 'name' column in the {key_value} table, the insertion of the ID in {key_value} will fail. Thus we test if we can use the plain ID or we need to store a hashed version of the entity ID. Also, it is not possible to rely on the UUID as entity types might not have one or might use a non-standard format.

The code is inspired by \Drupal\Core\Cache\DatabaseBackend::normalizeCid().

Parameters

int|string $entity_id: The entity id for which to compute the key.

Return value

int|string The key used to store the value in the key-value store.

See also

\Drupal\Core\Cache\DatabaseBackend::normalizeCid()

4 calls to PathautoState::getPathautoStateKey()
PathautoState::bulkDelete in src/PathautoState.php
Deletes the URL aliases for multiple entities of the same type.
PathautoState::getOriginalValue in src/PathautoState.php
Gets the data value currently stored in database.
PathautoState::persist in src/PathautoState.php
Persists the state.
PathautoState::purge in src/PathautoState.php
Deletes the stored state.

File

src/PathautoState.php, line 177

Class

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

Namespace

Drupal\pathauto

Code

public static function getPathautoStateKey($entity_id) {
  $entity_id_is_ascii = mb_check_encoding($entity_id, 'ASCII');
  if ($entity_id_is_ascii && strlen($entity_id) <= 128) {

    // The original entity ID, if it's an ASCII of 128 characters or less.
    return $entity_id;
  }
  return Crypt::hashBase64($entity_id);
}