function LanguageNegotiationUrlFallback::getLangcode

Same name in other branches
  1. 9 core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrlFallback.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrlFallback::getLangcode()
  2. 10 core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrlFallback.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrlFallback::getLangcode()
  3. 11.x core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrlFallback.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrlFallback::getLangcode()

Overrides LanguageNegotiationMethodInterface::getLangcode

File

core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrlFallback.php, line 48

Class

LanguageNegotiationUrlFallback
Class that determines the language to be assigned to URLs when none is detected.

Namespace

Drupal\language\Plugin\LanguageNegotiation

Code

public function getLangcode(Request $request = NULL) {
    $langcode = NULL;
    if ($this->languageManager) {
        $default = $this->languageManager
            ->getDefaultLanguage();
        $config = $this->config
            ->get('language.negotiation')
            ->get('url');
        $prefix = $config['source'] == LanguageNegotiationUrl::CONFIG_PATH_PREFIX;
        // If the default language is not configured to convey language
        // information, a missing URL language information indicates that URL
        // language should be the default one, otherwise we fall back to an
        // already detected language.
        if ($prefix && empty($config['prefixes'][$default->getId()]) || !$prefix && empty($config['domains'][$default->getId()])) {
            $langcode = $default->getId();
        }
        else {
            $langcode = $this->languageManager
                ->getCurrentLanguage()
                ->getId();
        }
    }
    return $langcode;
}

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