function LanguageNegotiator::negotiateLanguage

Same name in other branches
  1. 9 core/modules/language/src/LanguageNegotiator.php \Drupal\language\LanguageNegotiator::negotiateLanguage()
  2. 8.9.x core/modules/language/src/LanguageNegotiator.php \Drupal\language\LanguageNegotiator::negotiateLanguage()
  3. 11.x core/modules/language/src/LanguageNegotiator.php \Drupal\language\LanguageNegotiator::negotiateLanguage()

Performs language negotiation using the specified negotiation method.

Parameters

string $type: The language type to be initialized.

string $method_id: The string identifier of the language negotiation method to use to detect language.

Return value

\Drupal\Core\Language\LanguageInterface|null Negotiated language object for given type and method, FALSE otherwise.

1 call to LanguageNegotiator::negotiateLanguage()
LanguageNegotiator::initializeType in core/modules/language/src/LanguageNegotiator.php

File

core/modules/language/src/LanguageNegotiator.php, line 192

Class

LanguageNegotiator
Class responsible for performing language negotiation.

Namespace

Drupal\language

Code

protected function negotiateLanguage($type, $method_id) {
    $langcode = NULL;
    $method = $this->negotiatorManager
        ->getDefinition($method_id);
    if (!isset($method['types']) || in_array($type, $method['types'])) {
        $langcode = $this->getNegotiationMethodInstance($method_id)
            ->getLangcode($this->requestStack
            ->getCurrentRequest());
    }
    $languages = $this->languageManager
        ->getLanguages();
    return $languages[$langcode] ?? NULL;
}

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