Index: pathauto.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto.module,v
retrieving revision 1.146
diff -u -p -r1.146 pathauto.module
--- pathauto.module	16 Mar 2010 06:35:11 -0000	1.146
+++ pathauto.module	24 Mar 2010 20:34:56 -0000
@@ -132,6 +132,11 @@ function pathauto_path_alias_types() {
 function pathauto_pattern_load_by_entity($entity, $bundle = '', $language = LANGUAGE_NONE) {
   $patterns = &drupal_static(__FUNCTION__, array());
 
+  // @todo Remove this hack for taxonomy terms.
+  if ($entity == 'taxonomy_term') {
+    $entity = 'taxonomy';
+  }
+
   $pattern_id = "$entity:$bundle:$language";
   if (!isset($patterns[$pattern_id])) {
     $variables = array();
@@ -155,6 +160,67 @@ function pathauto_pattern_load_by_entity
   return $patterns[$pattern_id];
 }
 
+/**
+ * Add the automatic alias form elements to an existing path form fieldset.
+ */
+function pathauto_entity_path_edit_form(&$form, $entity_type, $entity) {
+  list($id, , $bundle) = entity_extract_ids($entity_type, $entity);
+
+  // @todo Remove this hack for taxonomy terms.
+  if ($entity_type == 'taxonomy_term') {
+    $bundle = $entity->vid;
+  }
+
+  $pattern = pathauto_pattern_load_by_entity($entity_type, $bundle, $form['language']['#value']);
+  if (!$pattern) {
+    return;
+  }
+
+  if (!isset($entity->pathauto_perform_alias)) {
+    if (empty($id)) {
+      module_load_include('inc', 'pathauto');
+      $pathauto_alias = pathauto_create_alias($entity_type, 'return', $form['source']['#value'], array($entity_type => $entity), $bundle, $form['language']['#value']);
+      $entity->pathauto_perform_alias = !empty($form['alias']['#default_value']) && $form['alias']['#default_value'] == $pathauto_alias;
+    }
+    else {
+      $entity->pathauto_perform_alias = TRUE;
+    }
+  }
+
+  $form['alias']['#states']['!enabled']['input[name="path[pathauto_perform_alias]"]'] = array('checked' => TRUE);
+
+  // Override path.module's vertical tabs summary.
+  $form['#attached']['js'] = array(
+    'vertical-tabs' => drupal_get_path('module', 'pathauto') . '/pathauto.js'
+  );
+
+  $form['pathauto_perform_alias'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Automatic alias'),
+    '#default_value' => $entity->pathauto_perform_alias,
+    '#description' => t('An alias will be generated for you using the pattern %pattern. If you wish to create your own alias below, uncheck this option.', array('%pattern' => $pattern)),
+    '#weight' => -10,
+  );
+
+  if (user_access('administer pathauto')) {
+    $form['pathauto_perform_alias']['#description'] .= ' ' . t('To control the format of the generated aliases, see the <a href="@url-patterns">URL alias patterns</a>.', array('@url-patterns' => url('admin/config/search/path/patterns')));
+  }
+
+  if ($entity->pathauto_perform_alias && !empty($entity->old_alias) && empty($form['alias'])) {
+    $form['alias']['#default_value'] = $entity->old_alias;
+  }
+
+  // For Pathauto to remember the old alias and prevent the Path-module from deleteing it when Pathauto wants to preserve it
+  if (!empty($entity->old_alias)) {
+    $form['old_alias'] = array(
+      '#type' => 'value',
+      '#value' => $entity->old_alias,
+    );
+  }
+
+  return $form;
+}
+
 //==============================================================================
 // Some node related functions.
 
@@ -224,63 +290,22 @@ function pathauto_form_alter(&$form, &$f
   // Process only node forms.
   if (!empty($form['#node_edit_form'])) {
     $node = $form['#node'];
-
-    // Find if there is an automatic alias pattern for this node type.
-    $language = isset($node->language) ? $node->language : LANGUAGE_NONE;
-    $pattern = pathauto_pattern_load_by_entity('node', $node->type, $language);
-
-    // If there is a pattern, show the automatic alias checkbox.
-    if ($pattern) {
-      if (!isset($node->pathauto_perform_alias)) {
-        if (!empty($node->nid)) {
-          // If this is not a new node, compare it's current alias to the
-          // alias that would be genereted by pathauto. If they are the same,
-          // then keep the automatic alias enabled.
-          _pathauto_include();
-          $path = path_load(array('source' => 'node/' . $node->nid));
-          $pathauto_alias = pathauto_create_alias('node', 'return', "node/{$node->nid}", array('node' => $node), $node->type, $node->language);
-          $node->pathauto_perform_alias = !empty($path['alias']) && $path['alias'] == $pathauto_alias;
-        }
-        else {
-          // If this is a new node, enable the automatic alias.
-          $node->pathauto_perform_alias = TRUE;
-        }
-      }
-
-      // Add JavaScript that will disable the path textfield when the automatic
-      // alias checkbox is checked.
-      $form['path']['alias']['#states']['!enabled']['input[name="path[pathauto_perform_alias]"]'] = array('checked' => TRUE);
-
-      // Override path.module's vertical tabs summary.
-      $form['path']['#attached']['js'] = array(
-        'vertical-tabs' => drupal_get_path('module', 'pathauto') . '/pathauto.js'
-      );
-
-      $form['path']['pathauto_perform_alias'] = array(
-        '#type' => 'checkbox',
-        '#title' => t('Automatic alias'),
-        '#default_value' => $node->pathauto_perform_alias,
-        '#description' => t('An alias will be generated for you. If you wish to create your own alias below, uncheck this option.'),
-        '#weight' => -1,
-      );
-
-      if (user_access('administer pathauto')) {
-        $form['path']['pathauto_perform_alias']['#description'] .= ' ' . t('To control the format of the generated aliases, see the <a href="@url-patterns">URL alias patterns</a>.', array('@url-patterns' => url('admin/config/search/path/patterns')));
-      }
-
-      if ($node->pathauto_perform_alias && !empty($node->old_alias) && empty($path['alias'])) {
-        $form['path']['alias']['#default_value'] = $node->old_alias;
-        $path['alias'] = $node->old_alias;
-      }
-
-      // For Pathauto to remember the old alias and prevent the Path-module from deleteing it when Pathauto wants to preserve it
-      if (!empty($path['alias'])) {
-        $form['path']['old_alias'] = array(
-          '#type' => 'value',
-          '#value' => $path['alias'],
-        );
-      }
-    }
+    pathauto_entity_path_edit_form($form['path'], 'node', $node);
+  }
+  if ($form_id == 'taxonomy_form_term') {
+    $form['path'] += array(
+      '#type' => 'fieldset',
+      '#title' => t('URL path settings'),
+      '#collapsible' => TRUE,
+      '#collapsed' => empty($path['alias']['#default_value']),
+      '#group' => 'additional_settings',
+      '#attached' => array(
+        'js' => array(drupal_get_path('module', 'path') . '/path.js'),
+      ),
+      '#weight' => 30,
+    );
+    $term = (object) $form['#term'];
+    pathauto_entity_path_edit_form($form['path'], 'taxonomy_term', $term);
   }
 }
 
