install_select_language

install_select_language(&$install_state)

Selects which language to use during installation.

Parameters

$install_state: An array of information about the current installation state. The chosen langcode will be added here, if it was not already selected previously, as will a list of all available languages.

Return value

For interactive installations, a form or other page output allowing the language to be selected or providing information about language selection, if a language has not been chosen. Otherwise, an exception is thrown if a language cannot be chosen automatically.

File

core/includes/install.core.inc, line 1276
API functions for installing Drupal.

Code

function install_select_language(&$install_state) {
  // Find all available translation files.
  $files = install_find_translations();
  $install_state['translations'] += $files;

  // If a valid language code is set, continue with the next installation step.
  // When translations from the localization server are used, any language code
  // is accepted because the standard language list is kept in sync with the
  // languages available at http://localize.drupal.org.
  // When files from the translation directory are used, we only accept
  // languages for which a file is available.
  if (!empty($install_state['parameters']['langcode'])) {
    $standard_languages = LanguageManager::getStandardLanguageList();
    $langcode = $install_state['parameters']['langcode'];
    if ($langcode == 'en' || isset($files[$langcode]) || isset($standard_languages[$langcode])) {
      $install_state['parameters']['langcode'] = $langcode;
      return;
    }
  }

  if (empty($install_state['parameters']['langcode'])) {
    // If we are performing an interactive installation, we display a form to
    // select a right language. If no translation files were found in the
    // translations directory, the form shows a list of standard languages. If
    // translation files were found the form shows a select list of the
    // corresponding languages to choose from.
    if ($install_state['interactive']) {
      return install_get_form('Drupal\Core\Installer\Form\SelectLanguageForm', $install_state);
    }
    // If we are performing a non-interactive installation. If only one language
    // (English) is available, assume the user knows what he is doing. Otherwise
    // throw an error.
    else {
      if (count($files) == 1) {
        $install_state['parameters']['langcode'] = current(array_keys($files));
        return;
      }
      else {
        throw new InstallerException(t('You must select a language to continue the installation.'));
      }
    }
  }
}
doc_Drupal
2016-10-29 09:21:03
Comments
Leave a Comment

Please login to continue.