You are here

public function ImportForm::submitForm in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/locale/src/Form/ImportForm.php \Drupal\locale\Form\ImportForm::submitForm()
  2. 10 core/modules/locale/src/Form/ImportForm.php \Drupal\locale\Form\ImportForm::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

core/modules/locale/src/Form/ImportForm.php, line 173

Class

ImportForm
Form constructor for the translation import screen.

Namespace

Drupal\locale\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $this->moduleHandler
    ->loadInclude('locale', 'translation.inc');

  // Add language, if not yet supported.
  $language = $this->languageManager
    ->getLanguage($form_state
    ->getValue('langcode'));
  if (empty($language)) {
    $language = ConfigurableLanguage::createFromLangcode($form_state
      ->getValue('langcode'));
    $language
      ->save();
    $this
      ->messenger()
      ->addStatus($this
      ->t('The language %language has been created.', [
      '%language' => $this
        ->t($language
        ->label()),
    ]));
  }
  $options = array_merge(_locale_translation_default_update_options(), [
    'langcode' => $form_state
      ->getValue('langcode'),
    'overwrite_options' => $form_state
      ->getValue('overwrite_options'),
    'customized' => $form_state
      ->getValue('customized') ? LOCALE_CUSTOMIZED : LOCALE_NOT_CUSTOMIZED,
  ]);
  $this->moduleHandler
    ->loadInclude('locale', 'bulk.inc');
  $file = locale_translate_file_attach_properties($this->file, $options);
  $batch = locale_translate_batch_build([
    $file->uri => $file,
  ], $options);
  batch_set($batch);

  // Create or update all configuration translations for this language.
  if ($batch = locale_config_batch_update_components($options, [
    $form_state
      ->getValue('langcode'),
  ])) {
    batch_set($batch);
  }
  $form_state
    ->setRedirect('locale.translate_page');
}