function AliasRepository::addLanguageFallback

Same name in other branches
  1. 9 core/modules/path_alias/src/AliasRepository.php \Drupal\path_alias\AliasRepository::addLanguageFallback()
  2. 10 core/modules/path_alias/src/AliasRepository.php \Drupal\path_alias\AliasRepository::addLanguageFallback()
  3. 11.x 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/lib/Drupal/Core/Path/AliasRepository.php
AliasRepository::lookupBySystemPath in core/lib/Drupal/Core/Path/AliasRepository.php
AliasRepository::preloadPathAlias in core/lib/Drupal/Core/Path/AliasRepository.php

File

core/lib/Drupal/Core/Path/AliasRepository.php, line 137

Class

AliasRepository
Provides the default path alias lookup operations.

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

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