function LanguageHooks::processLanguageSelect

Same name and namespace in other branches
  1. 11.x core/modules/language/src/Hook/LanguageHooks.php \Drupal\language\Hook\LanguageHooks::processLanguageSelect()

Processes a language select list form element.

Parameters

array $element: The form element to process.

Return value

array The processed form element.

File

core/modules/language/src/Hook/LanguageHooks.php, line 373

Class

LanguageHooks
Hook implementations for language.

Namespace

Drupal\language\Hook

Code

public function processLanguageSelect(array $element) : array {
  // Don't set the options if another module (translation, for example)
  // already set the options.
  if (!isset($element['#options'])) {
    $element['#options'] = [];
    foreach (\Drupal::languageManager()->getLanguages($element['#languages']) as $langcode => $language) {
      $element['#options'][$langcode] = $language->isLocked() ? $this->t('- @name -', [
        '@name' => $language->getName(),
      ]) : $language->getName();
    }
  }
  return $element;
}

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