You are here

function tmgmt_ui_translation_review_form_submit in Translation Management Tool 7

Submit callback for the job item review form.

2 string references to 'tmgmt_ui_translation_review_form_submit'
tmgmt_ui_translation_review_form_reject_confirm in ui/tmgmt_ui.module
Form callback for the reject confirm form.
_tmgmt_ui_review_form_element in ui/tmgmt_ui.module
Build form elements for the review form using flatened data items.

File

ui/tmgmt_ui.module, line 905
Common Translation managment UI.

Code

function tmgmt_ui_translation_review_form_submit($form, &$form_state) {

  /** @var TMGMTJobItem $item */
  $item = $form_state['item'];

  // First invoke the submit method on the source controller.
  $source = tmgmt_source_ui_controller($item->plugin);
  $source
    ->reviewFormSubmit($form, $form_state, $item);

  // Invoke the submit method on the translator controller (if available).
  if ($item
    ->getTranslator()) {
    $translator = tmgmt_translator_ui_controller($item
      ->getTranslator()->plugin);
    $translator
      ->reviewFormSubmit($form, $form_state, $item);
  }

  // Write changes back to item.
  foreach ($form_state['values'] as $key => $value) {
    if (is_array($value) && isset($value['translation'])) {

      // Update the translation, this will only update the translation in case
      // it has changed.
      $data = array(
        '#text' => $value['translation'],
        '#origin' => 'local',
      );
      $item
        ->addTranslatedData($data, $key);
    }
  }

  // Check if the user clicked on 'Accept', 'Submit' or 'Reject'.
  if (!empty($form['actions']['accept']) && $form_state['triggering_element']['#value'] == $form['actions']['accept']['#value']) {
    $item
      ->acceptTranslation();

    // Check if the item could be saved and accepted successfully and redirect
    // to the job item view if that is the case.
    if ($item
      ->isAccepted()) {
      $uri = $item
        ->uri();
      $form_state['redirect'] = $uri['path'];
    }

    // Print all messages that have been saved while accepting the reviewed
    // translation.
    foreach ($item
      ->getMessagesSince() as $message) {

      // Ignore debug messages.
      if ($message->type == 'debug') {
        continue;
      }
      if ($text = $message
        ->getMessage()) {
        drupal_set_message(filter_xss($text), $message->type);
      }
    }
  }
  $item
    ->save();
}