diff --git a/sites/all/modules/cck/includes/content.admin.inc b/sites/all/modules/cck/includes/content.admin.inc index d41e93c..affd3de 100644 --- a/sites/all/modules/cck/includes/content.admin.inc +++ b/sites/all/modules/cck/includes/content.admin.inc @@ -1337,8 +1337,14 @@ function content_field_edit_form_submit_update_basic($form, &$form_state) { $form_state['rebuild'] = TRUE; } +function version_id_filter_callback($item, $version_id_array) { + return count($item) >= 3 && in_array($item['vid'], $version_id_array); +} + /** * Save a field's settings after editing. + * In addition, the previous taxonomy terms associated with a node will now transfered + * to the corresponding content_taxonomy_field table. */ function content_field_edit_form_submit($form, &$form_state) { module_load_include('inc', 'content', 'includes/content.crud'); @@ -1354,6 +1360,62 @@ function content_field_edit_form_submit($form, &$form_state) { $type = content_types($form_values['type_name']); $form_state['redirect'] = 'admin/content/node-type/'. $type['url_str'] .'/fields'; } + + $save_term_node = $form_state['values']['save_term_node']; + $content_type = $form_state['values']['type_name']; + $vocabulary_id = $form_state['values']['vid']; + $field = $form_state['values']['field_name']; + + // Check to see if the "Save values additionally to the core taxonomy system (into the 'term_node' table)." + // checkbox is checked in the content field taxonomy configure page. + if ($save_term_node == 1) { + $node_ids = db_query("SELECT nid FROM node WHERE type = '$content_type'"); + while ($row = db_fetch_array($node_ids)) { + $node_id_array[] = $row['nid']; + } + + $resource = db_query("SELECT tid FROM term_data WHERE vid = '$vocabulary_id'"); + while ($row = db_fetch_array($resource)) { + $termId[] = $row['tid']; + } + + foreach($termId as $tid) { + $resource = db_query("SELECT * FROM term_node WHERE tid = $tid"); + while ($row = db_fetch_array($resource)) { + $term_node[] = $row; + } + } + + // Filter out all of the term_nodes that corresponds to the content types of the selected vocabulary/category + $filter_term_node = array_filter($term_node, function ($item) use ($node_id_array) { + return in_array($item['nid'], $node_id_array); + }); + + // Remove default populated rows. + db_query("DELETE FROM content_".$field." WHERE (".$field."_value IS NULL OR ".$field."_value = '')"); + + // Array for storing every content_field entry; need it to efficiently check for duplicate entries + // rather than querying the db. + $term_node_entry_array = array(); + foreach ($filter_term_node as $entry) { + $vid = intval($entry['vid']); + $nid = intval($entry['nid']); + $tid = intval($entry['tid']); + + if (!array_key_exists($nid, $term_node_entry_array)) { + $term_node_entry_array[$nid] = array(); // Make new array if entry is new + array_push(&$term_node_entry_array[$nid], $vid); + } else { // Otherwise add to an existing entry array. + array_push(&$term_node_entry_array[$nid], $vid); + } + + $tidCount = array_count_values($term_node_entry_array[$nid]); + $delta = $tidCount[$vid]-1; + $result = db_query("INSERT INTO content_".$field." VALUES ($vid, $nid, $delta, $tid)"); + } + } }