You are here

public function AliasStorage::lookupPathSource in Multiversion 8

Returns Drupal system URL of an alias.

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

Parameters

string $path: The path to investigate for corresponding system URLs.

string $langcode: Language code to search the path with. If there's no path defined for that language it will search paths without language.

Return value

string|false A Drupal system path, or FALSE if no path was found.

Overrides AliasStorage::lookupPathSource

File

src/AliasStorage.php, line 239

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 lookupPathSource($path, $langcode) {
  if (!$this->connection
    ->schema()
    ->fieldExists('url_alias', 'workspace')) {
    return parent::lookupPathSource($path, $langcode);
  }
  $alias = $this->connection
    ->escapeLike($path);
  $langcode_list = [
    $langcode,
    LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ];

  // See the queries above. Use LIKE for case-insensitive matching.
  $select = $this->connection
    ->select(static::TABLE)
    ->fields(static::TABLE, [
    'source',
  ])
    ->condition('alias', $alias, 'LIKE')
    ->condition('workspace', [
    $this->workspaceManager
      ->getActiveWorkspaceId(),
    0,
  ], 'IN');
  if ($langcode == LanguageInterface::LANGCODE_NOT_SPECIFIED) {
    array_pop($langcode_list);
  }
  elseif ($langcode > LanguageInterface::LANGCODE_NOT_SPECIFIED) {
    $select
      ->orderBy('langcode', 'DESC');
  }
  else {
    $select
      ->orderBy('langcode', 'ASC');
  }
  $select
    ->orderBy('pid', 'DESC');
  $select
    ->condition('langcode', $langcode_list, 'IN');
  try {
    return $select
      ->execute()
      ->fetchField();
  } catch (\Exception $e) {
    $this
      ->catchException($e);
    return FALSE;
  }
}