diff --git a/taxonomy_multi_edit.module b/taxonomy_multi_edit.module index f06d484..bb4bda9 100644 --- a/taxonomy_multi_edit.module +++ b/taxonomy_multi_edit.module @@ -136,7 +136,8 @@ function taxonomy_multi_edit_form_alter($form_id, &$form) { */ function taxonomy_multi_edit_content_form_alter(&$form){ // support bulk classifications - $form['options']['operation']['#options']['categorize'] = "Assign to a taxonomy term"; + $form['options']['operation']['#options']['categorize'] = t('Assign to a taxonomy term'); + $form['options']['operation']['#options']['uncategorize'] = t('Remove from a taxonomy term'); $form['options']['operation']['#attributes']['onchange'] = 'changedOperation(this)'; $form['options']['terms-wrapper'] = array( @@ -183,6 +184,25 @@ function taxonomy_multi_edit_content_form_submit($form,$edit){ cache_clear_all(); drupal_set_message(t('Terms have been updated for the selected nodes.')); } + else if ($edit['operation'] == 'uncategorize') { + $terms = $edit['terms']; + foreach ($edit['nodes'] as $nid => $value) { + if($value){ + // I could have done this direct to database, + // but we'll do it safer via the published methods instead. + // Means we can safely merge instead of overwrite + + $existing = taxonomy_node_get_terms($nid); + foreach($terms as $t){ // cannot array_merge as it messes the indexes + unset($existing[$t]); + } + taxonomy_node_save($nid,$existing); + drupal_set_message(t('Updated terms on node '.l($node->title?$node->title:$nid, "node/$nid"))); + } + } + cache_clear_all(); + drupal_set_message(t('Terms have been updated for the selected nodes.')); + } } function taxonomy_multi_edit_content_form_javascript(){ @@ -195,7 +215,8 @@ function taxonomy_multi_edit_content_form_javascript(){ function changedOperation(elem){ var term_div = $('#edit-terms-wrapper'); if(!term_div) return; - if(elem.options[elem.selectedIndex].value == 'categorize'){ + if((elem.options[elem.selectedIndex].value == 'categorize') || + (elem.options[elem.selectedIndex].value == 'uncategorize')) { term_div.show(); } else { term_div.hide();