function AliasRepository::addLanguageFallback

Same name and namespace in other branches
  1. 9 core/modules/path_alias/src/AliasRepository.php \Drupal\path_alias\AliasRepository::addLanguageFallback()
  2. 8.9.x core/lib/Drupal/Core/Path/AliasRepository.php \Drupal\Core\Path\AliasRepository::addLanguageFallback()
  3. 10 core/modules/path_alias/src/AliasRepository.php \Drupal\path_alias\AliasRepository::addLanguageFallback()

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 AliasRepository::addLanguageFallback()
AliasRepository::lookupByAlias in core/modules/path_alias/src/AliasRepository.php
AliasRepository::lookupBySystemPath in core/modules/path_alias/src/AliasRepository.php
AliasRepository::preloadPathAlias in core/modules/path_alias/src/AliasRepository.php

File

core/modules/path_alias/src/AliasRepository.php, line 133

Class

AliasRepository
Provides the default path alias lookup operations.

Namespace

Drupal\path_alias

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');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.