function LocaleFormHooks::formLanguageAdminAddFormAlterSubmit

Same name and namespace in other branches
  1. main core/modules/locale/src/Hook/LocaleFormHooks.php \Drupal\locale\Hook\LocaleFormHooks::formLanguageAdminAddFormAlterSubmit()

Form submission handler for language_admin_add_form.

Set a batch for a newly-added language.

File

core/modules/locale/src/Hook/LocaleFormHooks.php, line 130

Class

LocaleFormHooks
Form hook implementations for locale.

Namespace

Drupal\locale\Hook

Code

public function formLanguageAdminAddFormAlterSubmit(array $form, FormStateInterface $form_state) : void {
  $options = LocaleDefaultOptions::updateOptions();
  if ($form_state->isValueEmpty('predefined_langcode') || $form_state->getValue('predefined_langcode') == 'custom') {
    $langcode = $form_state->getValue('langcode');
  }
  else {
    $langcode = $form_state->getValue('predefined_langcode');
  }
  if ($this->importEnabled()) {
    // Download and import translations for the newly added language.
    $batch = ($this->localeFetchClosure)()
      ->buildUpdateBatch([], [
      $langcode,
    ], $options);
    batch_set($batch);
  }
  // Create or update all configuration translations for this language. If we
  // are adding English then we need to run this even if import is not
  // enabled, because then we extract English sources from shipped
  // configuration.
  if ($this->importEnabled() || $langcode == 'en') {
    if ($batch = ($this->localeConfigBatchClosure)()
      ->buildBatch($options, [
      $langcode,
    ])) {
      batch_set($batch);
    }
  }
}

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