diff -urpN old/workflow_ng/workflow_ng/modules/workflow_ng_taxonomy.inc new/workflow_ng/workflow_ng/modules/workflow_ng_taxonomy.inc --- old/workflow_ng/workflow_ng/modules/workflow_ng_taxonomy.inc 1970-01-01 02:00:00.000000000 +0200 +++ new/workflow_ng/workflow_ng/modules/workflow_ng_taxonomy.inc 2008-05-20 16:09:11.968750000 +0300 @@ -0,0 +1,181 @@ + array( + 'file' => 'workflow_ng_taxonomy_forms.inc', + 'file path' => drupal_get_path('module', 'workflow_ng') .'/modules/', + ), + ); +} + +/** + * Implementation of hook_action_info(). + */ +function taxonomy_action_info() { + $info = array(); + $info['workflow_ng_action_load_vocabulary'] = array( + '#label' => t('Load vocabulary'), + '#new arguments' => array( + 'vocabulary' => array('#entity' => 'vocabulary', '#label' => t('Vocabulary')), + ), + '#description' => t("Load an exisiting vocabulary as a new argument. This should be used before 'Add and load new term'."), + '#module' => 'Taxonomy', + ); + $info['workflow_ng_action_add_vocabulary'] = array( + '#label' => t('Add and load vocabulary'), + '#new arguments' => array( + 'vocabulary' => array('#entity' => 'vocabulary', '#label' => t('Vocabulary')), + ), + '#description' => t("Create a new vocabulary and load it as a new argument. This should be used before 'Add and load new term'."), + '#module' => 'Taxonomy', + ); + $info['workflow_ng_action_load_term'] = array( + '#label' => t('Load term'), + '#new arguments' => array( + 'term' => array('#entity' => 'term', '#label' => t('Term')), + ), + '#description' => t('Load an exisiting term as a new argument.'), + '#module' => 'Taxonomy', + ); + $info['workflow_ng_action_add_term'] = array( + '#label' => t('Add and load term'), + '#arguments' => array( + 'vocabulary' => array('#entity' => 'vocabulary', '#label' => t('Vocabulary which term will be added to')) + ), + '#new arguments' => array( + 'term' => array('#entity' => 'term', '#label' => t('Term')), + ), + '#description' => t("Add and load a term to a loaded vocabulary. Note that this action is meant for adding simple terms, which means it doesn't + deal with 'Synonyms', 'Parents' and 'Related terms' if they are enabled."), + '#module' => 'Taxonomy', + ); + $info['workflow_ng_action_add_term_to_content'] = array( + '#label' => t('Add a loaded term to content'), + '#arguments' => array( + 'node' => array('#entity' => 'node', '#label' => t('Content which term will added to')), + 'term' => array('#entity' => 'term', '#label' => t('Term which will be added')), + ), + '#description' => t('Loaded term will be added to the loaded content.'), + '#module' => 'Taxonomy', + ); + $info['workflow_ng_action_remove_term_from_content'] = array( + '#label' => t('Remove a loaded term from content'), + '#arguments' => array( + 'node' => array('#entity' => 'node', '#label' => t('Content which term will removed from')), + 'term' => array('#entity' => 'term', '#label' => t('Term which will be removed')), + ), + '#description' => t('Loaded term will be removed from the loaded content.'), + '#module' => 'Taxonomy', + ); + return $info; +} + +/** + * Action: Load vocabulary. + */ +function workflow_ng_action_load_vocabulary($settings, &$arguments, &$log) { + if ($settings['vocabulary_token']) { + extract(workflow_ng_token_replace_all(array('vocabulary_token'), $settings, $arguments, $log)); + $vid = $vocabulary_token; + } + else { + $vid = $settings['vocabulary_list']; + } + $return = taxonomy_get_vocabulary($vid); + if (!empty($return)) { + return array('#new arguments' => array('vocabulary' => $return)); + } +} + +/** + * Action: Add and load a new vocabulary. + */ +function workflow_ng_action_add_vocabulary($settings, &$arguments, &$log) { + extract(workflow_ng_token_replace_all(array('name', 'description', 'help'), $settings, $arguments, $log)); + // Update settings according to token replacemnts. + $settings['name'] = $name; + $settings['description'] = $description; + $settings['help'] = $help; + + $settings['weight'] = $settings['weight_vocabulary']; + taxonomy_save_vocabulary($settings); + // Settings has now the vid. + $return = taxonomy_get_vocabulary($settings['vid']); + return array('#new arguments' => array('vocabulary' => $return)); +} + +/** + * Action: Load term. + */ +function workflow_ng_action_load_term($settings, &$arguments, &$log) { + if ($settings['term_token']) { + extract(workflow_ng_token_replace_all(array('term_token'), $settings, $arguments, $log)); + $tid = $term_token; + } + else { + $tid = $settings['term_list']; + } + $return = taxonomy_get_term($tid); + if (!empty($return)) { + return array('#new arguments' => array('term' => $return)); + } +} + + +/** + * Action: Add a term to a loaded vocabulary. + */ +function workflow_ng_action_add_term($vocabulary, $settings, &$arguments, &$log) { + extract(workflow_ng_token_replace_all(array('name', 'description'), $settings, $arguments, $log)); + // Update settings according to token replacemnts. + $settings['name'] = $name; + $settings['description'] = $description; + + $settings['weight'] = $settings['weight_vocabulary']; + + // Set the vid from the loaded vocabulary argument. + $settings['vid'] = $vocabulary->vid; + + // Check if term already exists in vocabulary. + if ($settings['existing_term'] && $terms = taxonomy_get_term_by_name($name)) { + // Check if matching term is from same vocabulary. + foreach ($terms as $term) { + if ($term->vid == $vocabulary->vid) { + // Term exists. Load the existing term and break. + $return = taxonomy_get_term($term->tid); + break; + } + } + } + else { + taxonomy_save_term($settings); + $return = taxonomy_get_term($settings['tid']); + } + return array('#new arguments' => array('term' => $return)); +} + +/** + * Action: Add a loaded term to a loaded content. + */ +function workflow_ng_action_add_term_to_content($node, $term, $settings, &$arguments, &$log) { + $node->taxonomy[$term->tid] = $term; + return array('node' => $node); +} + + +/** + * Action: Remove a loaded term from a loaded content. + */ +function workflow_ng_action_remove_term_from_content($node, $term, $settings, &$arguments, &$log) { + unset($node->taxonomy[$term->tid]); + return array('node' => $node); +} \ No newline at end of file diff -urpN old/workflow_ng/workflow_ng/modules/workflow_ng_taxonomy_forms.inc new/workflow_ng/workflow_ng/modules/workflow_ng_taxonomy_forms.inc --- old/workflow_ng/workflow_ng/modules/workflow_ng_taxonomy_forms.inc 1970-01-01 02:00:00.000000000 +0200 +++ new/workflow_ng/workflow_ng/modules/workflow_ng_taxonomy_forms.inc 2008-05-20 16:07:21.718750000 +0300 @@ -0,0 +1,173 @@ + $vocabulary) { + $options[$key] = $vocabulary->name; + } + $options ? $description = t('Select the vocabulary that should be loaded.') : $description = t('There are no exisiting vocabularies. Create a vocabulary manually through the !url or using a workflow_ng action.', + array('!url' => l('settings', 'admin/content/taxonomy'))); + $form = array(); + $form['vocabulary_list'] = array( + '#type' => 'select', + '#title' => t('Vocabulary by list'), + '#description' => $description, + '#options' => $options, + '#default_value' => $settings['vocabulary_list'], + '#disabled' => empty($options), + ); + $form['vocabulary_token'] = array( + '#type' => 'textfield', + '#title' => t('Vocabulary by text'), + '#description' => t('Enter the vocabulary id (vid) of the exisiting vocabulary.'), + '#default_value' => $settings['vocabulary_token'], + ); + workflow_ng_token_replacement_help($form, $argument_info); + return $form; +} + +function workflow_ng_action_load_vocabulary_submit($form_id, $form_values) { + $token = workflow_ng_token_get_settings(array('vocabulary_token'), $form_values); + $settings = array('vocabulary_list' => $form_values['vocabulary_list'], 'vocabulary_token' => $form_values['vocabulary_token']); + return $token + $settings; +} + +/** + * Action: Add and load a new vocabulary form. + * + * @ingroup forms + * @see workflow_ng_action_add_vocabulary_submit + */ +function workflow_ng_action_add_vocabulary_form($settings = array(), $argument_info) { + // Pass the corect weight settings - weight vocabulary + $settings['weight'] = $settings['weight_vocabulary']; + $form = taxonomy_form_vocabulary($settings); + // Change vocabuly weight name in order to prevent name collision. + $form['weight_vocabulary'] = $form['weight']; + unset($form['weight']); + unset($form['submit']); + workflow_ng_token_replacement_help($form, $argument_info); + return $form; +} + +function workflow_ng_action_add_vocabulary_submit($form_id, $form_values) { + $token = workflow_ng_token_get_settings(array('name', 'description', 'help'), $form_values); + $form_list = array( + 'name', + 'description', + 'help', + 'nodes', + 'hierarchy', + 'relations', + 'tags', + 'multiple', + 'required', + 'weight_vocabulary', + ); + foreach ($form_list as $form_item) { + $settings[$form_item] = $form_values[$form_item]; + } + + // Remove node types which are not set. + $settings['nodes'] = array_filter($settings['nodes']); + + return $token + $settings; +} + +/** + * Action: Load term form. + * + * @ingroup forms + * @see workflow_ng_action_load_term_submit + */ +function workflow_ng_action_load_term_form($settings = array(), $argument_info) { + //We still don't have the vocabulary. + $terms = taxonomy_form_all(); + $options = array(); + // Get the options grouped by vocabulary. + foreach ($terms as $key => $term) { + $options[$key] = $term; + } + $options ? $description = t('Select the term that should be loaded.') : $description = t('There are no exisiting terms.'); + $form = array(); + $form['term_list'] = array( + '#type' => 'select', + '#title' => t('Term by list'), + '#description' => $description, + '#options' => $options, + '#default_value' => $settings['term_list'], + '#disabled' => empty($options), + ); + $form['term_token'] = array( + '#type' => 'textfield', + '#title' => t('Term by text'), + '#description' => t('Enter the term id (tid) of the exisiting term.'), + '#default_value' => $settings['term_token'], + ); + workflow_ng_token_replacement_help($form, $argument_info); + return $form; +} + +function workflow_ng_action_load_term_submit($form_id, $form_values) { + $token = workflow_ng_token_get_settings(array('term_token'), $form_values); + $settings = array('term_list' => $form_values['term_list'], 'term_token' => $form_values['term_token']); + return $token + $settings; +} + +/** + * Action: Add a term to a loaded vocabulary form. + * + * @ingroup forms + * @see workflow_ng_action_add_term_to_content_submit + */ +function workflow_ng_action_add_term_form($settings = array(), $argument_info) { + // Pass the corect weight settings - weight vocabulary + $settings['weight_vocabulary'] ? $settings['weight'] = $settings['weight_vocabulary'] : $settings['weight'] = 0; + // We still don't know the vid. + $form = taxonomy_form_term(0, $settings); + $form['existing_term'] = array( + '#type' => 'checkbox', + '#title' => t('Check if term already exists'), + '#default_value' => $settings['existing_term'], + '#description' => t('Check if the term already exists in the vocabulary. If so, the existing term will be loaded.'), + ); + + // Change vocabuly weight name in order to prevent name collision. + $form['weight_vocabulary'] = $form['weight']; + // We can't get synonyms as we still don't have tid. + unset($form['synonyms']); + unset($form['weight']); + unset($form['destination']); + unset($form['submit']); + workflow_ng_token_replacement_help($form, $argument_info); + + return $form; +} + + +function workflow_ng_action_add_term_submit($form_id, $form_values) { + $token = workflow_ng_token_get_settings(array('name', 'description'), $form_values); + $form_list = array( + 'name', + 'description', + 'existing_term', + 'weight_vocabulary', + ); + foreach ($form_list as $form_item) { + $settings[$form_item] = $form_values[$form_item]; + } + return $token + $settings; +} +