You are here

public function AliasStorage::load in Multiversion 8

Fetches a specific URL alias from the database.

The default implementation performs case-insensitive matching on the 'source' and 'alias' strings.

Parameters

array $conditions: An array of query conditions.

Return value

array|false FALSE if no alias was found or an associative array containing the following keys:

  • source (string): The internal system path with a starting slash.
  • alias (string): The URL alias with a starting slash.
  • pid (int): Unique path alias identifier.
  • langcode (string): The language code of the alias.

Overrides AliasStorage::load

File

src/AliasStorage.php, line 169

Class

AliasStorage
Extends the core AliasStore class. We need this to make possible aliases to work with Multiversion and Replication.

Namespace

Drupal\multiversion

Code

public function load($conditions) {
  if (!$this->connection
    ->schema()
    ->fieldExists('url_alias', 'workspace')) {
    return parent::load($conditions);
  }
  $select = $this->connection
    ->select(static::TABLE);
  $select
    ->condition('workspace', [
    $this->workspaceManager
      ->getActiveWorkspaceId(),
    0,
  ], 'IN');
  foreach ($conditions as $field => $value) {
    if ($field == 'source' || $field == 'alias') {

      // Use LIKE for case-insensitive matching.
      $select
        ->condition($field, $this->connection
        ->escapeLike($value), 'LIKE');
    }
    else {
      $select
        ->condition($field, $value);
    }
  }
  try {
    return $select
      ->fields(static::TABLE)
      ->orderBy('pid', 'DESC')
      ->range(0, 1)
      ->execute()
      ->fetchAssoc();
  } catch (\Exception $e) {
    $this
      ->catchException($e);
    return FALSE;
  }
}