You are here

protected function TranslationTargetLanguageFilter::getValidLangcode in Translation Views 8

Get a valid langcode from language options.

Parameters

string $target_langcode: Target language identifier.

array $language_options: Available language options.

Return value

string|null A valid langcode, or NULL if no valid langcodes exist.

1 call to TranslationTargetLanguageFilter::getValidLangcode()
TranslationTargetLanguageFilter::valueForm in src/Plugin/views/filter/TranslationTargetLanguageFilter.php
Options form subform for setting options.

File

src/Plugin/views/filter/TranslationTargetLanguageFilter.php, line 249

Class

TranslationTargetLanguageFilter
Provides filtering by translation target language.

Namespace

Drupal\translation_views\Plugin\views\filter

Code

protected function getValidLangcode($target_langcode, array $language_options) {
  if ($target_langcode === '***LANGUAGE_site_default***') {
    $target_langcode = $this->languageManager
      ->getDefaultLanguage()
      ->getId();
  }
  elseif ($target_langcode === '***LANGUAGE_language_interface***') {
    $target_langcode = $this->languageManager
      ->getCurrentLanguage()
      ->getId();
  }
  if (!isset($language_options[$target_langcode]) && !empty($language_options)) {
    return array_keys($language_options)[0];
  }
  elseif (empty($language_options)) {
    return NULL;
  }
  return $target_langcode;
}