You are here

function lingotek_entity_disassociate_form_submit in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lingotek.bulk_grid.inc \lingotek_entity_disassociate_form_submit()
  2. 7.5 lingotek.bulk_grid.inc \lingotek_entity_disassociate_form_submit()

Submit handler for the lingotek_entity_disassociate form.

1 string reference to 'lingotek_entity_disassociate_form_submit'
lingotek_entity_disassociate_form in ./lingotek.bulk_grid.inc
Form constructor for the entity disassociate form. (Formerly "Reset Translations")

File

./lingotek.bulk_grid.inc, line 2170

Code

function lingotek_entity_disassociate_form_submit($form, $form_state) {
  if (isset($form_state['values']['entity_ids'])) {
    $drupal_entity_ids_json = json_decode($form_state['values']['entity_ids']);
  }
  elseif (isset($form_state['entity_ids'])) {
    $drupal_entity_ids_json = json_decode($form_state['entity_ids']);
  }
  $entity_type = isset($form_state['entity_type']) ? $form_state['entity_type'] : 'node';
  $entity_ids = array();
  foreach ($drupal_entity_ids_json as $id) {
    $entity_ids[] = $id;
  }
  $doc_ids = LingotekSync::getDocIdsFromEntityIds($entity_type, $entity_ids);
  $api = LingotekApi::instance();
  $remove_from_tms = $form_state['values']['confirm'];
  if ($remove_from_tms) {

    //disassociate on TMS
    $result = lingotek_batch_disassociate_content_worker($api, $doc_ids);
    if (!$result) {
      drupal_set_message(t('Failed to remove documents from Lingotek TMS.'), 'warning', FALSE);
      return;
    }
  }
  lingotek_keystore_delete_multiple($entity_type, $entity_ids, 'document_id');
  lingotek_keystore_delete_multiple($entity_type, $entity_ids, 'upload_status');
  lingotek_keystore_delete_multiple($entity_type, $entity_ids, 'original_language');
  lingotek_keystore_delete_multiple($entity_type, $entity_ids, 'source_language_%', 'LIKE');
  foreach ($entity_ids as $entity_id) {
    LingotekSync::setAllTargetStatus($entity_type, $entity_id, LingotekSync::STATUS_UNTRACKED);
  }
  drupal_set_message(format_plural(count($entity_ids), 'Translations disassociated for one entity.', 'Translations disassociated for @count entities.'));
}