function ConfigTranslateForm::submitForm

File

sources/tmgmt_config/src/Form/ConfigTranslateForm.php, line 189

Class

ConfigTranslateForm
Configuration translation overview form.

Namespace

Drupal\tmgmt_config\Form

Code

function submitForm(array &$form, FormStateInterface $form_state) {

  /** @var \Drupal\config_translation\ConfigMapperManagerInterface $mapper */
  $mapper = $form_state
    ->get('mapper');
  $values = $form_state
    ->getValues();
  $item_type = $form_state
    ->get('item_type');
  $item_id = $form_state
    ->get('item_id');
  $jobs = array();
  foreach (array_keys(array_filter($values['languages'])) as $langcode) {

    // Create the job object.
    $job = tmgmt_job_create($mapper
      ->getLangcode(), $langcode, \Drupal::currentUser()
      ->id());
    try {

      // Add the job item.
      $job
        ->addItem('config', $item_type, $item_id);

      // Append this job to the array of created jobs so we can redirect the user
      // to a multistep checkout form if necessary.
      $jobs[$job
        ->id()] = $job;
    } catch (TMGMTException $e) {
      watchdog_exception('tmgmt', $e);
      $languages = \Drupal::languageManager()
        ->getLanguages();
      $target_lang_name = $languages[$langcode]->language;
      $this
        ->messenger()
        ->addError(t('Unable to add job item for target language %name. Make sure the source content is not empty.', array(
        '%name' => $target_lang_name,
      )));
    }
  }
  \Drupal::service('tmgmt.job_checkout_manager')
    ->checkoutAndRedirect($form_state, $jobs);
}