You are here

public function RequestTranslationApproveForm::submitForm in TMGMT Extension Suite 8

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

src/Form/RequestTranslationApproveForm.php, line 252

Class

RequestTranslationApproveForm

Namespace

Drupal\tmgmt_extension_suit\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $this
    ->refreshServices();

  // Pass data from private storage appended by form data to batch.
  $data = $this->tempStore
    ->get('request_translation_batch');
  $data['target_language'] = array_filter($form_state
    ->getValue('target_language'));
  $data['translator'] = $form_state
    ->getValue('translator');
  $data['settings'] = $form_state
    ->getValue('settings');
  $conflicting_items = [];
  $operations = [];
  foreach ($data['items'] as $item) {
    $operation_data = $data;
    $operation_data['item'] = $item;
    unset($operation_data['items']);
    foreach ($operation_data['target_language'] as $language) {
      $operation_data['target_language'] = $language;
      $result = $this
        ->getConflictingItem($operation_data, $language);
      if (!empty($result)) {
        $job_item_id = key($result);
        $conflicting_items[$job_item_id] = $this
          ->t('@job_item_link with source language = "@source_language" and target language = "@target_language" for entity "@entity_type" with id = "@id".', [
          '@job_item_link' => Link::fromTextAndUrl(t('Job item'), Url::fromRoute('entity.tmgmt_job_item.canonical', [
            'tmgmt_job_item' => $job_item_id,
          ], [
            'attributes' => [
              'target' => '_blank',
            ],
          ]))
            ->toString(),
          '@entity_type' => $operation_data['item_type'],
          '@id' => $operation_data['item'],
          '@source_language' => $operation_data['source_language'],
          '@target_language' => $language,
        ]);
      }
      else {
        $operations[] = [
          [
            get_class($this),
            'processBatch',
          ],
          [
            $operation_data,
          ],
        ];
      }
    }
  }
  if (!empty($conflicting_items)) {
    drupal_set_message($this
      ->getConflictMessage($conflicting_items), 'warning');
  }
  $this->tempStore
    ->set('request_translation_batch', []);
  if (!empty($operations)) {

    // Set up batch.
    $batch = [
      'title' => t('Requesting translations...'),
      'operations' => $operations,
      'finished' => [
        get_class($this),
        'finishBatch',
      ],
    ];
    batch_set($batch);
  }
  else {
    drupal_set_message(Link::fromTextAndUrl(t('Return to "Sources" page'), Url::fromRoute('tmgmt.source_overview_default'))
      ->toString());
  }
}