You are here

function lingotek_entity_disassociate_form_submit in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.5 lingotek.bulk_grid.inc \lingotek_entity_disassociate_form_submit()
  2. 7.6 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 3235

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();
  lingotek_keystore_delete_multiple($entity_type, $entity_ids, 'document_id');
  LingotekSync::setAllUploadStatuses($entity_type, $entity_ids, LingotekSync::STATUS_NONE);
  lingotek_keystore_delete_multiple($entity_type, $entity_ids, 'original_language');
  LingotekSync::bulkSetAllTargetStatus($entity_type, $entity_ids, LingotekSync::STATUS_NONE);
  foreach ($entity_ids as $entity_id) {

    // find which translations exist on Drupal for the entity
    $existing_translations = lingotek_get_languages($entity_type, $entity_id);

    // find which targets have a status within Lingotek
    $target_locales = LingotekSync::getAllTargetStatusForEntity($entity_type, $entity_id);

    // for each existing translation, set the target status to untracked
    foreach ($existing_translations as $language) {
      $locale = Lingotek::convertDrupal2Lingotek($language);
      if (isset($target_locales[$locale])) {
        LingotekSync::setTargetStatus($entity_type, $entity_id, $locale, LingotekSync::STATUS_UNTRACKED);
        unset($target_locales[$locale]);
      }
    }
  }
  $disassociated_entities = '(Entity ID\'s: ';
  for ($i = 0; $i < count($entity_ids); $i++) {
    if ($i == count($entity_ids) - 1) {
      $disassociated_entities .= $entity_ids[$i] . ')';
    }
    else {
      $disassociated_entities .= $entity_ids[$i] . ', ';
    }
  }
  drupal_set_message(format_plural(count($entity_ids), 'Translations disassociated for one entity. ' . $disassociated_entities, 'Translations disassociated for @count entities. ' . $disassociated_entities));
}