You are here

private function LanguageSelectionPageSubscriber::getLanguage in Language Selection Page 8.2

Callback helper.

Return value

array|bool The language to use, or FALSE.

1 call to LanguageSelectionPageSubscriber::getLanguage()
LanguageSelectionPageSubscriber::redirectToLanguageSelectionPage in src/EventSubscriber/LanguageSelectionPageSubscriber.php
Event callback.

File

src/EventSubscriber/LanguageSelectionPageSubscriber.php, line 143

Class

LanguageSelectionPageSubscriber
Provides a LanguageSelectionPageSubscriber.

Namespace

Drupal\language_selection_page\EventSubscriber

Code

private function getLanguage() {

  // Get all methods available for the user interface language type.
  $methods = $this->configFactory
    ->get('language.types')
    ->get('negotiation.' . LanguageInterface::TYPE_INTERFACE . '.enabled') ?: [];

  // We ignore this language method or else it will always return a language.
  unset($methods[LanguageNegotiationSelected::METHOD_ID]);
  foreach ($methods as $method_id => $method_definition) {

    // Do not consider methods with a lower priority than the language
    // selection page method, nor the language selection page method itself.
    if ($method_id === LanguageNegotiationLanguageSelectionPage::METHOD_ID) {
      return FALSE;
    }
    $lang = $this->languageNegotiator
      ->getNegotiationMethodInstance($method_id)
      ->getLangcode($this->event
      ->getRequest());
    if ($lang) {
      return $lang;
    }
  }

  // If no other language was found, use the default one.
  return $this->languageManager
    ->getDefaultLanguage()
    ->getId();
}