You are here

public function LingotekJobAssignToMultipleConfigForm::submitForm in Lingotek Translation 3.3.x

Same name and namespace in other branches
  1. 8.2 src/Form/LingotekJobAssignToMultipleConfigForm.php \Drupal\lingotek\Form\LingotekJobAssignToMultipleConfigForm::submitForm()
  2. 4.0.x src/Form/LingotekJobAssignToMultipleConfigForm.php \Drupal\lingotek\Form\LingotekJobAssignToMultipleConfigForm::submitForm()
  3. 3.0.x src/Form/LingotekJobAssignToMultipleConfigForm.php \Drupal\lingotek\Form\LingotekJobAssignToMultipleConfigForm::submitForm()
  4. 3.1.x src/Form/LingotekJobAssignToMultipleConfigForm.php \Drupal\lingotek\Form\LingotekJobAssignToMultipleConfigForm::submitForm()
  5. 3.2.x src/Form/LingotekJobAssignToMultipleConfigForm.php \Drupal\lingotek\Form\LingotekJobAssignToMultipleConfigForm::submitForm()
  6. 3.4.x src/Form/LingotekJobAssignToMultipleConfigForm.php \Drupal\lingotek\Form\LingotekJobAssignToMultipleConfigForm::submitForm()
  7. 3.5.x src/Form/LingotekJobAssignToMultipleConfigForm.php \Drupal\lingotek\Form\LingotekJobAssignToMultipleConfigForm::submitForm()
  8. 3.6.x src/Form/LingotekJobAssignToMultipleConfigForm.php \Drupal\lingotek\Form\LingotekJobAssignToMultipleConfigForm::submitForm()
  9. 3.7.x src/Form/LingotekJobAssignToMultipleConfigForm.php \Drupal\lingotek\Form\LingotekJobAssignToMultipleConfigForm::submitForm()
  10. 3.8.x src/Form/LingotekJobAssignToMultipleConfigForm.php \Drupal\lingotek\Form\LingotekJobAssignToMultipleConfigForm::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

1 call to LingotekJobAssignToMultipleConfigForm::submitForm()
LingotekJobClearMultipleConfigForm::submitForm in src/Form/LingotekJobClearMultipleConfigForm.php
Form submission handler.
1 method overrides LingotekJobAssignToMultipleConfigForm::submitForm()
LingotekJobClearMultipleConfigForm::submitForm in src/Form/LingotekJobClearMultipleConfigForm.php
Form submission handler.

File

src/Form/LingotekJobAssignToMultipleConfigForm.php, line 189

Class

LingotekJobAssignToMultipleConfigForm
Form for bulk assignation of Job ID to config entities.

Namespace

Drupal\lingotek\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $job_id = $form_state
    ->getValue('job_id');
  $updateTMS = $form_state
    ->getValue('update_tms');
  $errors = FALSE;
  $mappers = $this
    ->getSelectedMappers($this->selection);
  foreach ($mappers as $mapper) {
    if ($mapper instanceof ConfigEntityMapper) {
      try {
        $entity = $mapper
          ->getEntity();
        $this->translationService
          ->setJobId($entity, $job_id, $updateTMS);
      } catch (LingotekPaymentRequiredException $exception) {
        $errors = TRUE;
        $this->messenger
          ->addError(t('Community has been disabled. Please contact support@lingotek.com to re-enable your community.'));
      } catch (LingotekDocumentArchivedException $exception) {
        $errors = TRUE;
        $this->messenger
          ->addError(t('Document @entity_type %title has been archived. Please upload again.', [
          '@entity_type' => $entity
            ->getEntityTypeId(),
          '%title' => $entity
            ->label(),
        ]));
      } catch (LingotekDocumentLockedException $exception) {
        $errors = TRUE;
        $this->messenger
          ->addError(t('Document @entity_type %title has a new version. The document id has been updated for all future interactions. Please try again.', [
          '@entity_type' => $entity
            ->getEntityTypeId(),
          '%title' => $entity
            ->label(),
        ]));
      } catch (LingotekApiException $exception) {
        $errors = TRUE;
        $this
          ->messenger()
          ->addError(t('The Job ID change submission for @entity_type %title failed. Please try again.', [
          '@entity_type' => $entity
            ->getEntityTypeId(),
          '%title' => $entity
            ->label(),
        ]));
      }
    }
    else {
      try {
        $this->translationService
          ->setConfigJobId($mapper, $job_id, $updateTMS);
      } catch (LingotekPaymentRequiredException $exception) {
        $errors = TRUE;
        $this->messenger
          ->addError(t('Community has been disabled. Please contact support@lingotek.com to re-enable your community.'));
      } catch (LingotekDocumentArchivedException $exception) {
        $errors = TRUE;
        $this->messenger
          ->addError(t('Document %label has been archived. Please upload again.', [
          '%label' => $mapper
            ->getTitle(),
        ]));
      } catch (LingotekDocumentLockedException $exception) {
        $errors = TRUE;
        $this->messenger
          ->addError(t('Document %label has a new version. The document id has been updated for all future interactions. Please try again.', [
          '%label' => $mapper
            ->getTitle(),
        ]));
      } catch (LingotekApiException $exception) {
        $errors = TRUE;
        $this->messenger
          ->addError(t('The Job ID change submission for %label failed. Please try again.', [
          '%label' => $mapper
            ->getTitle(),
        ]));
      }
    }
  }
  $form_state
    ->setRedirectUrl(Url::fromUserInput('/' . $form_state
    ->getValue('destination')));
  if (!$errors) {
    $this
      ->postStatusMessage();
  }
  else {
    $this->messenger
      ->addWarning($this
      ->t('Job ID for some config failed to sync to the TMS.'));
  }

  // Clear selected data.
  $this->tempStore
    ->delete($this->currentUser
    ->id());
}