You are here

protected function FieldTimerCountdownFormatter::getLanguage in Field Timer 8

Same name and namespace in other branches
  1. 2.x src/Plugin/Field/FieldFormatter/FieldTimerCountdownFormatter.php \Drupal\field_timer\Plugin\Field\FieldFormatter\FieldTimerCountdownFormatter::getLanguage()

Gets language to use for jquery.countdown.

Parameters

string $langcode: Language code.

Return value

string Language code.

2 calls to FieldTimerCountdownFormatter::getLanguage()
FieldTimerCountdownFormatter::preparePluginSettings in src/Plugin/Field/FieldFormatter/FieldTimerCountdownFormatter.php
Prepares array of settings used to initialize jQuery plugin.
FieldTimerCountdownFormatter::viewElements in src/Plugin/Field/FieldFormatter/FieldTimerCountdownFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/FieldTimerCountdownFormatter.php, line 231

Class

FieldTimerCountdownFormatter
Plugin implementation of the 'field_timer_countdown' formatter.

Namespace

Drupal\field_timer\Plugin\Field\FieldFormatter

Code

protected function getLanguage($langcode) {

  // Fallback to English.
  $language = 'en';
  if ($this
    ->getSetting('use_system_language')) {
    $languages = $this
      ->languageOptions();

    // Try content language.
    if (isset($languages[$langcode])) {
      $language = $langcode;
    }
    else {
      $defaultLangcode = $this->languageDefault
        ->get()
        ->getId();

      // Try default language.
      if (isset($languages[$defaultLangcode])) {
        $language = $defaultLangcode;
      }
    }
  }
  else {
    $language = $this
      ->getSetting('regional');
  }
  return $language;
}