You are here

function tmgmt_job_form_submit in Translation Management Tool 7

Submit callback for the job checkout form.

File

ui/includes/tmgmt_ui.pages.inc, line 701
Provides page callbacks and form functions for the Translation Management Tool User Interface module.

Code

function tmgmt_job_form_submit($form, &$form_state) {

  // Build up the job from the submitted form values and save here so we got the
  // plain 'Submit' case covered. Also, if the translator fails it won't save on
  // its own.
  $job = entity_ui_form_submit_build_entity($form, $form_state);

  // If requested custom job settings handling, copy values from original job.
  if (tmgmt_job_settings_custom_handling($job
    ->getTranslator())) {
    $original_job = entity_load_unchanged('tmgmt_job', $job->tjid);
    $job->settings = $original_job->settings;
  }

  // Make sure that we always store a label as it can be a slow operation to
  // generate the default label.
  if (empty($job->label)) {
    $job->label = $job
      ->label();
  }
  $job
    ->save();

  // Per default we want to redirect the user to the overview.
  $form_state['redirect'] = 'admin/tmgmt';

  // Everything below this line is only invoked if the 'Submit to translator'
  // button was clicked.
  if ($form_state['triggering_element']['#value'] == $form['actions']['checkout']['#value']) {
    if (!tmgmt_ui_job_request_translation($job)) {

      // Don't redirect the user if the translation request failed but retain
      // existing destination parameters so we can redirect once the request
      // finished successfully.
      // @todo: Change this to stay on the form in case of an error instead of
      // doing a redirect.
      $form_state['redirect'] = array(
        current_path(),
        array(
          'query' => drupal_get_destination(),
        ),
      );
      unset($_GET['destination']);
    }
    else {
      if ($redirect = tmgmt_ui_redirect_queue_dequeue()) {

        // Proceed to the next redirect queue item, if there is one.
        $form_state['redirect'] = $redirect;
      }
      else {

        // Proceed to the defined destination if there is one.
        $form_state['redirect'] = tmgmt_ui_redirect_queue_destination($form_state['redirect']);
      }
    }
  }
}