You are here

protected function AliasStorage::addLanguageFallback in Drupal 8

Adds path alias language fallback conditions to a select query object.

Parameters

\Drupal\Core\Database\Query\SelectInterface $query: A Select query object.

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

3 calls to AliasStorage::addLanguageFallback()
AliasStorage::lookupPathAlias in core/lib/Drupal/Core/Path/AliasStorage.php
Returns an alias of Drupal system URL.
AliasStorage::lookupPathSource in core/lib/Drupal/Core/Path/AliasStorage.php
Returns Drupal system URL of an alias.
AliasStorage::preloadPathAlias in core/lib/Drupal/Core/Path/AliasStorage.php
Pre-loads path alias information for a given list of source paths.

File

core/lib/Drupal/Core/Path/AliasStorage.php, line 262

Class

AliasStorage
Provides a class for CRUD operations on path aliases.

Namespace

Drupal\Core\Path

Code

protected function addLanguageFallback(SelectInterface $query, $langcode) {

  // Always get the language-specific alias before the language-neutral one.
  // For example 'de' is less than 'und' so the order needs to be ASC, while
  // 'xx-lolspeak' is more than 'und' so the order needs to be DESC.
  $langcode_list = [
    $langcode,
    LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ];
  if ($langcode === LanguageInterface::LANGCODE_NOT_SPECIFIED) {
    array_pop($langcode_list);
  }
  elseif ($langcode > LanguageInterface::LANGCODE_NOT_SPECIFIED) {
    $query
      ->orderBy('base_table.langcode', 'DESC');
  }
  else {
    $query
      ->orderBy('base_table.langcode', 'ASC');
  }
  $query
    ->condition('base_table.langcode', $langcode_list, 'IN');
}