You are here

function lingotek_entity_delete_translations_form_submit in Lingotek Translation 7.7

Submit handler for the lingotek_entity_delete_translations form.

1 string reference to 'lingotek_entity_delete_translations_form_submit'
lingotek_entity_delete_translations_form in ./lingotek.bulk_grid.inc
Form constructor for the translations delete.

File

./lingotek.bulk_grid.inc, line 3128

Code

function lingotek_entity_delete_translations_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;
  }
  if ($entity_type == 'menu_link') {
    lingotek_delete_menu_link_translations($entity_ids);
  }
  else {

    // Deletes translations based on whether it is node based translation or field based translation
    if (!empty($entity_ids)) {
      $entities = entity_load($entity_type, $entity_ids);
      $count = 0;
      foreach ($entities as $entity) {
        $entity->lingotek_upload_override = FALSE;
        if ($entity_type == 'node' && lingotek_uses_node_translation($entity)) {
          $count += 1;
          lingotek_delete_node_translations($entity->nid);
        }
        if ($entity->tnid == 0) {
          $count += 1;
          lingotek_delete_field_translations($entity_type, $entity);
        }
      }
    }
  }
  watchdog('content', format_plural($count, 'Deleted translations for 1 entity.', 'Deleted translations for @count entities.'));
  drupal_set_message(format_plural($count, 'Deleted translations for 1 entity.', 'Deleted translations for @count entities.'));
  $form_state['redirect'] = LINGOTEK_MENU_MAIN_BASE_URL . '/manage';
  return lingotek_grid_filter_submit($form, $form_state);
}