### Eclipse Workspace Patch 1.0
#P drupal
Index: modules/taxonomy/taxonomy.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.admin.inc,v
retrieving revision 1.63
diff -u -r1.63 taxonomy.admin.inc
--- modules/taxonomy/taxonomy.admin.inc	20 Jul 2009 18:51:34 -0000	1.63
+++ modules/taxonomy/taxonomy.admin.inc	30 Jul 2009 10:44:15 -0000
@@ -672,17 +672,21 @@
 function taxonomy_form_term(&$form_state, $vocabulary, $edit = array()) {
   $edit += array(
     'name' => '',
+    'path' => '',
     'description' => '',
     'vocabulary_machine_name' => $vocabulary->machine_name,
     'tid' => NULL,
     'weight' => 0,
   );
 
+  // If the term path is set.
+  $edit['path'] = $edit['tid'] ? drupal_lookup_path('alias', 'taxonomy/term/' . $edit['tid']) : '';
+  
   // Take into account multi-step rebuilding.
   if (isset($form_state['term'])) {
     $edit = $form_state['term'] + $edit;
   }
-
+  
   $parent = array_keys(taxonomy_get_parents($edit['tid']));
   $form['#term'] = $edit;
   $form['#term']['parent'] = $parent;
@@ -709,6 +713,18 @@
     '#default_value' => $edit['name'],
     '#maxlength' => 255,
     '#required' => TRUE);
+
+  // If path module is installed, let user set term path.
+  if (module_exists('path')) {
+    $form['identification']['path'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Term URL alias'),
+      '#default_value' => $edit['path'],
+      '#maxlength' => 255,
+      '#description' => t('Optionally specify an alternative URL by which this term can be accessed. Use a relative path and don\'t add a trailing slash or the URL alias won\'t work.'),
+    );
+  }
+  
   $form['identification']['description'] = array(
     '#type' => 'textarea',
     '#title' => t('Description'),
@@ -800,10 +816,20 @@
  *
  * @see taxonomy_form_term()
  */
-function taxonomy_form_term_submit($form, &$form_state) {
+function taxonomy_form_term_submit($form, &$form_state) { 
   if ($form_state['clicked_button']['#value'] == t('Delete')) {
     // Execute the term deletion.
     if ($form_state['values']['delete'] === TRUE) {
+      // If the term path is set, let's remove it from the url_alias table
+      $path = $form['#term']['path'];
+      $tid = $form['#term']['tid'];
+      if ($path && module_exists('path')) {
+        $src = 'taxonomy/term/' . $tid;
+        $pid = db_result(db_query('SELECT pid FROM {url_alias} WHERE src = :src', array(':src' => $src)));
+        module_invoke('path', 'set_alias', null, null, $pid);
+        drupal_set_message(t('Deleted term url: %path.', array('%path' => $path)));
+        watchdog('taxonomy', 'Deleted term url: %path.', array('%path' => $path), WATCHDOG_NOTICE);
+      }
       return taxonomy_term_confirm_delete_submit($form, $form_state);
     }
     // Rebuild the form to confirm term deletion.
@@ -821,11 +847,35 @@
   $term = taxonomy_form_term_submit_builder($form, $form_state);
 
   $status = taxonomy_term_save($term);
+  
+  // Add or Update term path
+  if ($term->path) {
+    $alias = $term->path;
+    $path = 'taxonomy/term/' . $term->tid;
+    
+    // For some reason path_set_alias() is not updating existing url aliases. Once the problem is found this code can be altered
+    $pid = db_result(db_query('SELECT pid FROM {url_alias} WHERE src = :src', array(':src' => $path)));    
+    if ($pid) {
+      // delete the existing term alias
+      module_invoke('path', 'set_alias', null, null, $pid); 
+      module_invoke('path', 'set_alias', $path, $alias);
+      drupal_set_message(t('Updated term url %path.', array('%path' => $term->path)));
+      watchdog('taxonomy', 'Updated term  url %path.', array('%path' => $term->path), WATCHDOG_NOTICE, l(t('edit'), 'taxonomy/term/' . $term->tid . '/edit'));
+    }
+    else {
+      module_invoke('path', 'set_alias', $path, $alias);
+      
+      drupal_set_message(t('Created new term url %path.', array('%path' => $term->path)));
+      watchdog('taxonomy', 'Created new term  url %path.', array('%path' => $term->path), WATCHDOG_NOTICE, l(t('edit'), 'taxonomy/term/' . $term->tid . '/edit'));
+    }
+  }
+  
   switch ($status) {
     case SAVED_NEW:
       drupal_set_message(t('Created new term %term.', array('%term' => $term->name)));
       watchdog('taxonomy', 'Created new term %term.', array('%term' => $term->name), WATCHDOG_NOTICE, l(t('edit'), 'taxonomy/term/' . $term->tid . '/edit'));
       break;
+      
     case SAVED_UPDATED:
       drupal_set_message(t('Updated term %term.', array('%term' => $term->name)));
       watchdog('taxonomy', 'Updated term %term.', array('%term' => $term->name), WATCHDOG_NOTICE, l(t('edit'), 'taxonomy/term/' . $term->tid . '/edit'));
