You are here

function select_translation_parse_mode in Select translation 8

Parse the mode argument.

Parse the mode argument and replace 'current' and 'default' with the actual language codes.

Parameters

string $mode: A string describing the mode, see the documentation below.

Return value

array An array of language codes representing the order of preference to use when selecting a translation, the value 'original' is used for the original translation.

2 calls to select_translation_parse_mode()
SelectTranslation::query in src/Plugin/views/filter/SelectTranslation.php
Executes the query.
select_translation_of_node in ./select_translation.module
Returns the selected translation of the given node.

File

./select_translation.module, line 25
Main module file.

Code

function select_translation_parse_mode($mode) {
  if ($mode == 'original') {
    $lang_list = [
      'current',
    ];
  }
  elseif ($mode == 'default') {
    $lang_list = [
      'current',
      'default',
    ];
  }
  else {
    $lang_list = explode(',', $mode);
    foreach ($lang_list as $i => $v) {
      $lang_list[$i] = strtolower(trim($v));
    }
  }
  $lang_list[] = 'original';
  $default_language = \Drupal::languageManager()
    ->getDefaultLanguage()
    ->getId();
  $current_language = \Drupal::languageManager()
    ->getCurrentLanguage(LanguageInterface::TYPE_INTERFACE)
    ->getId();
  foreach ($lang_list as $i => $v) {
    if ($v == 'default') {
      $lang_list[$i] = $default_language;
    }
    elseif ($v == 'current') {
      $lang_list[$i] = $current_language;
    }
  }
  return array_unique($lang_list);
}