You are here

function tft_manage_folders_form_submit in Taxonomy File Tree 7

Same name and namespace in other branches
  1. 7.2 includes/tft.pages.inc \tft_manage_folders_form_submit()

Form submission callback.

See also

tft_manage_folders_form()

File

./tft.admin.inc, line 302

Code

function tft_manage_folders_form_submit($form, &$form_state) {
  foreach ($form_state['values']['table'] as $key => $item) {
    if ($form['#use_hierarchy'] && $item['type'] == 'term') {
      db_update('taxonomy_term_hierarchy')
        ->fields(array(
        'parent' => $item['parent'],
      ))
        ->condition('tid', $item['id'])
        ->execute();
    }
    else {
      $node = node_load($item['id']);

      // Reconstruct list of terms by removing all folder terms.
      $node->tft_folder[LANGUAGE_NONE][0]['tid'] = $item['parent'];
      node_save($node);
    }
    if ($form['#use_weight']) {
      db_delete('tft_folder_content_weight')
        ->condition('type', $item['type'])
        ->condition('id', $item['id'])
        ->execute();
      db_insert('tft_folder_content_weight')
        ->fields(array(
        'id' => $item['id'],
        'type' => $item['type'],
        'parent_tid' => $form['#tid'],
        'weight' => $item['weight'],
      ))
        ->execute();
    }
    if ($item['type'] == 'term') {
      db_update('taxonomy_term_data')
        ->fields(array(
        'name' => $item['name'],
      ))
        ->condition('tid', $item['id'])
        ->execute();
    }
  }
}