You are here

function locale_form_language_admin_add_form_alter_submit in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/locale/locale.module \locale_form_language_admin_add_form_alter_submit()
  2. 10 core/modules/locale/locale.module \locale_form_language_admin_add_form_alter_submit()

Form submission handler for language_admin_add_form().

Set a batch for a newly-added language.

1 string reference to 'locale_form_language_admin_add_form_alter_submit'
locale_form_language_admin_add_form_alter in core/modules/locale/locale.module
Implements hook_form_FORM_ID_alter() for language_admin_add_form().

File

core/modules/locale/locale.module, line 687
Enables the translation of the user interface to languages other than English.

Code

function locale_form_language_admin_add_form_alter_submit($form, FormStateInterface $form_state) {
  \Drupal::moduleHandler()
    ->loadInclude('locale', 'fetch.inc');
  $options = _locale_translation_default_update_options();
  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 (\Drupal::config('locale.settings')
    ->get('translation.import_enabled')) {

    // Download and import translations for the newly added language.
    $batch = locale_translation_batch_update_build([], [
      $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 (\Drupal::config('locale.settings')
    ->get('translation.import_enabled') || $langcode == 'en') {
    \Drupal::moduleHandler()
      ->loadInclude('locale', 'bulk.inc');
    if ($batch = locale_config_batch_update_components($options, [
      $langcode,
    ])) {
      batch_set($batch);
    }
  }
}