? .project ? sites/all/modules/coder ? sites/all/modules/devel ? sites/default/.DS_Store ? sites/default/files ? sites/default/settings.php Index: modules/taxonomy/taxonomy.module =================================================================== RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v retrieving revision 1.481 diff -u -p -r1.481 taxonomy.module --- modules/taxonomy/taxonomy.module 27 Jun 2009 19:49:07 -0000 1.481 +++ modules/taxonomy/taxonomy.module 28 Jun 2009 12:26:38 -0000 @@ -1825,3 +1825,70 @@ function taxonomy_hook_info() { ), ); } + +/** + * Implementation of hook_action_info(). + */ +function taxonomy_action_info() { + $actions = array( + 'taxonomy_term_add_action' => array( + 'type' => 'node', + 'description' => t('Add a taxonomy term to a node.'), + 'configurable' => TRUE, + 'hooks' => array( + 'node' => array('presave'), + ), + 'behavior' => array('changes_node_property'), + ), + ); + return $actions; +} + +/** + * Implements a taxonomy term action to add terms to nodes. + */ +function taxonomy_term_add_action($node, $context) { + $term = taxonomy_term_load($context['term']); + if ($term == FALSE) return ; + $vocs = taxonomy_get_vocabularies($node->type); + if (array_key_exists($term->vid, $vocs)) { + $voc = $vocs[$term->vid]; + // For multiple select vocabularies, terms are simply appended. + if ($voc->multiple) { + $node->taxonomy[$term->vid][] = $term->tid; + } + // For sinlge select vocabularies, terms may be overridden, depending on + // context. + elseif ($context['override'] || !isset($node->taxonomy[$term->vid])) { + $node->taxonomy[$term->vid] = $term->tid; + } + } +} + +/** + * Settings form for taxonomy_term_add_action. + */ +function taxonomy_term_add_action_form($context) { + $form['term'] = array( + '#type' => 'select', + '#title' => t('Taxonomy term'), + '#options' => taxonomy_form_all(), + '#description' => t('Select the term to be added to a node. The vocabulary has to be activated for the depending node type.'), + '#required' => TRUE, + '#default_value' => (isset($context['term'])) ? $context['term'] : NULL, + ); + $form['override'] = array( + '#type' => 'checkbox', + '#description' => t('When checked, an existing value will be overridden for non-multiple select vocabularies.'), + '#title' => t('Override single term'), + '#default_value' => (isset($context['override']) && $context['override']), + ); + return $form; +} + +/** + * Submit for settings form of taxonomy_term_add_action. + */ +function taxonomy_term_add_action_submit($form, $form_state) { + return array('term' => $form_state['values']['term'], 'override' => $form_state['values']['override']); +} \ No newline at end of file