function ConfigurableLanguageManager::getFallbackCandidates

Same name in other branches
  1. 9 core/modules/language/src/ConfigurableLanguageManager.php \Drupal\language\ConfigurableLanguageManager::getFallbackCandidates()
  2. 8.9.x core/modules/language/src/ConfigurableLanguageManager.php \Drupal\language\ConfigurableLanguageManager::getFallbackCandidates()
  3. 10 core/modules/language/src/ConfigurableLanguageManager.php \Drupal\language\ConfigurableLanguageManager::getFallbackCandidates()

Overrides LanguageManager::getFallbackCandidates

File

core/modules/language/src/ConfigurableLanguageManager.php, line 366

Class

ConfigurableLanguageManager
Overrides default LanguageManager to provide configured languages.

Namespace

Drupal\language

Code

public function getFallbackCandidates(array $context = []) {
    if ($this->isMultilingual()) {
        $candidates = [];
        if (empty($context['operation']) || $context['operation'] != 'locale_lookup') {
            // If the fallback context is not locale_lookup, initialize the
            // candidates with languages ordered by weight and add
            // LanguageInterface::LANGCODE_NOT_SPECIFIED at the end. Interface
            // translation fallback should only be based on explicit configuration
            // gathered via the alter hooks below.
            $candidates = array_keys($this->getLanguages());
            $candidates[] = LanguageInterface::LANGCODE_NOT_SPECIFIED;
            $candidates = array_combine($candidates, $candidates);
            // The first candidate should always be the desired language if
            // specified.
            if (!empty($context['langcode'])) {
                $candidates = [
                    $context['langcode'] => $context['langcode'],
                ] + $candidates;
            }
        }
        // Let other modules hook in and add/change candidates.
        $type = 'language_fallback_candidates';
        $types = [];
        if (!empty($context['operation'])) {
            $types[] = $type . '_' . $context['operation'];
        }
        $types[] = $type;
        $this->moduleHandler
            ->alter($types, $candidates, $context);
    }
    else {
        $candidates = parent::getFallbackCandidates($context);
    }
    return $candidates;
}

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