? edit_term/cvs
? edit_term/edit_term.png
? edit_term/install
Index: edit_term/CHANGELOG.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/edit_term/CHANGELOG.txt,v
retrieving revision 1.1
diff -u -p -r1.1 CHANGELOG.txt
--- edit_term/CHANGELOG.txt	14 Oct 2007 14:46:05 -0000	1.1
+++ edit_term/CHANGELOG.txt	8 Mar 2008 08:44:25 -0000
@@ -1,3 +1,10 @@
+Saturday 8 Mar 2008
+- @dman Integrated menu and alias editor from a private library
+  Basically a replacement to the module, as it's 80% new additions :)
+
+Sun 2 Mar 2008
+- @dman Added tab edit as per http://drupal.org/node/226484
+
 October 13, 2007
  - edit_term.module:
     o initial commit, for Drupal 5.0
Index: edit_term/README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/edit_term/README.txt,v
retrieving revision 1.1
diff -u -p -r1.1 README.txt
--- edit_term/README.txt	14 Oct 2007 14:46:05 -0000	1.1
+++ edit_term/README.txt	8 Mar 2008 08:44:26 -0000
@@ -11,14 +11,20 @@ Installation and configuration:
 Please refer to the INSTALL file for complete installation and 
 configuration instructions.
 
+When enabled, A new tab will be seen on taxonomy/term/n pages,
+and taxonomy/term/n/edit will provide 
+[URL path settings] and [Menu settings] within the normal form.
 
 Requires:
 --------
  - Drupal 5.0
  - enabled taxonomy.module
-
+ - optional : support for path.module
+ - optional : support for image_gallery.module
 
 Credits:
 -------
- - Written and maintained by Benjamin Melanon of Agaric Design Collective
+ - Written and maintained by Benjamin Melan�on of Agaric Design Collective
    http://agaricdesign.com/
+ - Term Editor additions by Dan Morrison (dman) 
+   http://coders.co.nz/
\ No newline at end of file
Index: edit_term/edit_term.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/edit_term/edit_term.info,v
retrieving revision 1.1
diff -u -p -r1.1 edit_term.info
--- edit_term/edit_term.info	14 Oct 2007 14:46:05 -0000	1.1
+++ edit_term/edit_term.info	8 Mar 2008 08:44:26 -0000
@@ -1,6 +1,6 @@
 ; $Id: edit_term.info,v 1.1 2007/10/14 14:46:05 agaric Exp $
 name = Edit term
-description = "Make it easy to get to a term edit page from the user interface front end."
+description = "Adds a link to the term editor from term page. Adds menu and path management to term edit pages."
 dependencies = taxonomy ; block is required core
 package = Taxonomy
-version = "$Name:  $"
+version = "$Name: DRUPAL-5 $"
Index: edit_term/edit_term.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/edit_term/edit_term.install,v
retrieving revision 1.1
diff -u -p -r1.1 edit_term.install
--- edit_term/edit_term.install	14 Oct 2007 14:46:05 -0000	1.1
+++ edit_term/edit_term.install	8 Mar 2008 08:44:27 -0000
@@ -7,8 +7,17 @@
  * No database schema required or planned, so no need for hook_install.
  */
 function edit_term_install() {
+  // Ensure this always runs AFTER menu.module and the rest of core has done its forms;
+  db_query("UPDATE {system} SET weight = 3 WHERE name = 'edit_term'");
   db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, pages) VALUES('edit_term', 'link', '%s', 1, -10, 'right', '')", variable_get('theme_default', 'garland'));
-  drupal_set_message(t('Installed edit term module and enabled the "Edit term link" block.  You can configure this block at @admin.', array(@admin => l(t('Administer  Site Building  Blocks'), 'admin/build/block'))));
+  drupal_set_message(t('
+    Installed edit term module and enabled the "Edit term link" block.  
+    You can configure this block at !admin.
+    Term Edit UI Enhancements to the Admin screens are now available. 
+    You should see new features when visiting term edit pages.
+    ', 
+    array('!admin' => l(t('Administer  Site Building  Blocks'), 'admin/build/block'))
+  ));
 }
 
 /**
Index: edit_term/edit_term.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/edit_term/edit_term.module,v
retrieving revision 1.1
diff -u -p -r1.1 edit_term.module
--- edit_term/edit_term.module	14 Oct 2007 14:46:05 -0000	1.1
+++ edit_term/edit_term.module	8 Mar 2008 08:44:28 -0000
@@ -1,13 +1,123 @@
 <?php
 // $Id: edit_term.module,v 1.1 2007/10/14 14:46:05 agaric Exp $
+/**
+ * @file
+ *
+ * Enhancements to the Drupal admin interface - make term management easier.
+ *
+ * This module adds a few usability elements to the Drupal term management
+ * screens:
+ * 
+ * Direct link to 'edit term' page when viewing taxonomy/term/n pages
+ * This enables quick acces right to the term description and heirarchy
+ * position, returning the admin user to where they were on save.
+ * Also works for 'gallery' management pages from the image_gallery.module 
+ * 
+ * An edit form for menu placement for the term on the term edit page. Create
+ * and position a menu link to taxonomy/term/n as needed. No need to trust
+ * taxonomy_menu, go through the admin - menu screens and juggle weights, or try
+ * or other strange navigations. Just add a menu item the same as you do for a
+ * node.
+ * 
+ * An edit form for term aliases. Again, like editing a node, just give your
+ * term page a path. Should co-operate with pathauto also.
+ *
+ * The UI additions integrate with image_gallery.module to display the term edit
+ * tab on gallery pages also, and to edit gallery paths and menus the same as
+ * term pages ... taking care to redirect to image/tid/n pages, not
+ * taxonomy/term/n pages.
+ *
+ * Credits:
+ * --------
+ * 
+ * Original edit_term 'block' feature
+ * @author Benjamin Melan�on of Agaric Design Collective, October 2007. http:
+ * //AgaricDesign.com
+ * 
+ * Usability additions
+ * - edit tabs
+ * - menu editor
+ * - alias editor
+ * @author Dan morrison (dman) http://coders.co.nz/ February 2008
+ * 
+ * @version $Id: $
+ */
+
+/**
+ * Return help text describing this module
+ *
+ * Implementation of hook_help().
+ */
+function edit_term_help($section) {
+  switch ($section) {
+    case 'admin/modules#description' :
+      return t("Enhancements to make term editing easier.");
+    case 'admin/help#edit_term':
+      return ' '; // Show me on the help menu, but don't execute all the time
+    case 'admin/help/edit_term':
+      return edit_term_about();
+  }
+  return false;
+}
 
 /**
-* @file
-* edit_term.module provides an easy way to .
-*
-* Written by Benjamin Melanon of Agaric Design Collective, October 2007.
-* http://AgaricDesign.com
-*/
+ * Hook Implimentation
+ * 
+ * Adds edit tab to taxonomy pages.
+ */
+function edit_term_menu($may_cache) {
+  $items = array();
+
+  if (arg(0) == 'taxonomy' && arg(1) == 'term') {
+    // Add an edit tab to taxonomy pages for easy access
+    // Need two dummy default items - parent and default - for the advanced tab to show :-/
+    // There may be an easier way
+    $items[] = array(
+      'path' => 'taxonomy/term/'. arg(2) , 
+      'type' => MENU_CALLBACK,
+    );
+    $items[] = array(
+      'path' => 'taxonomy/term/'. arg(2) .'/view' , 
+      'title' => t('View'),
+      'type' => MENU_DEFAULT_LOCAL_TASK,
+      'access' => TRUE,
+    );
+    $items[] = array(
+      'path' => 'taxonomy/term/'. arg(2) .'/edit' , 
+      'title' => t('Edit Term'),
+      'callback' => 'edit_term_edit_taxonomy_term',
+      'callback arguments' => array(arg(2)),
+      'access' => node_access('administer taxonomy'),
+      'weight' => 1,
+      'type' => MENU_LOCAL_TASK,
+    );
+  }
+  if (arg(0) == 'image' && arg(1) == 'tid') {
+    // Add an edit tab to gallery pages for easy access
+    // Needs default view tabs for the advanced tab to show :-/
+    $items[] = array(
+      'path' => 'image/tid/'. arg(2) , 
+      'type' => MENU_CALLBACK,
+    );
+    $items[] = array(
+      'path' => 'image/tid/'. arg(2) .'/view', 
+      'title' => t('View'),
+      'weight' => 0,
+      'type' => MENU_DEFAULT_LOCAL_TASK
+    );
+    $items[] = array(
+      'path' => 'image/tid/'. arg(2) .'/edit', 
+      'title' => t('Edit Gallery'),
+      'callback' => 'edit_term_edit_taxonomy_term',
+      'callback arguments' => array(arg(2)),
+      'access' => node_access('administer images'),
+      'weight' => 1,
+      'type' => MENU_LOCAL_TASK
+    );
+  }
+  return $items;
+}
+
 
 /**
  * Implementation of hook_block
@@ -50,11 +160,245 @@ function edit_term_block($op = 'list', $
           else {
             $name = $tid;
           }
-          $items[] = l(t('edit term') . ' ' . $name, 'admin/content/taxonomy/edit/term/' . $tid, array(), $destination);
+          $items[] = l(t('edit term') .' '. $name, 'admin/content/taxonomy/edit/term/'. $tid, array(), $destination);
         }
         $block['subject'] = t('Taxonomy term');
         $block['content'] = theme('item_list', $items);
       }
       return $block;
   }
-}
\ No newline at end of file
+}
+
+/**
+ * Redirect the extra tab to the taxonomy edit page.
+ */
+function edit_term_edit_taxonomy_term($tid) {
+  $term = taxonomy_get_term($tid);
+
+  $termpath = 'taxonomy/term/'. $tid;
+  if ( ($gvid = variable_get('image_gallery_nav_vocabulary', '')) && ($term->vid == $gvid)) {
+    $termpath = 'image/tid/'. $tid;
+  }
+  
+  $_REQUEST['destination'] = $termpath;
+
+  if ($term) {
+    drupal_set_title(t("Editing %term", array('%term' => $term->name)));
+    return taxonomy_admin_term_edit($tid);
+  }
+  else {
+    return t("Failed to load term");
+  }
+}
+
+/**
+ * Implementation of hook_form_alter().
+ * Add menu item fields to the term form.
+ * 
+ * copied from menu_form_alter()
+ */
+function edit_term_form_alter($form_id, &$form) {
+  if ($form_id == 'taxonomy_form_term') {
+    $term = taxonomy_get_term($form['tid']['#value']);
+    // Default form has no useful weighting on it.
+    // Add some
+    $form['submit']['#weight'] = 10;
+    $form['delete']['#weight'] = 11;
+
+    // Add the menu editor
+    edit_term_menu_form($term, &$form);
+
+    // Add the alias editor
+    if (module_exists('path')) {
+      edit_term_path_form($term, &$form);
+    }
+  }
+}
+
+/**
+ * Adds the menu edit function to term pages
+ * 
+ * Helper to edit_term_form_alter. Amends the $form by reference.
+ * 
+ * Pretty much a copy of menu_form_alter(), 
+ * It does the same thing as node edit forms do.
+ */
+function edit_term_menu_form($term, &$form) {
+  $item = array();
+  if ($form['tid']['#value'] > 0) {
+    $item = db_fetch_array(db_query("SELECT * FROM {menu} WHERE path = 'taxonomy/term/%d'", $form['tid']['#value']));
+    if (isset($form['#post']['menu']) && is_array($form['#post']['menu'])) {
+      $item = !is_array($item) ? $form['#post']['menu'] : (($form['#post']['op'] == t('Preview')) ? array_merge($item, $form['#post']['menu']) : array_merge($form['#post']['menu'], $item));
+    }
+  }
+
+  $form['menu'] = array('#type' => 'fieldset',
+    '#title' => t('Menu settings'),
+    '#access' => user_access('administer menu'),
+    '#collapsible' => TRUE,
+    '#collapsed' => empty($item['title']),
+    '#tree' => TRUE,
+    '#weight' => 5,
+  );
+
+  $form['menu']['domenu'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Create a menu item for this term'),
+    '#default_value' => ($item ? 1 : 0),
+  );
+
+  $form['menu']['title'] = array('#type' => 'textfield',
+    '#title' => t('Title'),
+    '#default_value' => $item['title'] ? $item['title'] : $term->name,
+    '#description' => t('The name to display for this menu link.'),
+  );
+
+  $form['menu']['description'] = array('#type' => 'textfield',
+    '#title' => t('Description'),
+    '#default_value' => $item['description'] ? $item['description'] : $term->description,
+    '#description' => t('The description displayed when hovering over a menu item.'),
+  );
+
+  // Generate a list of possible parents.
+  $options = menu_parent_options($item['mid'], variable_get('menu_parent_items', 0));
+
+  // If not set, Guess the most likely parent based on taxonomy heirarchy
+  if (! $item['pid'] && $parents = taxonomy_get_parents($term->tid) ) {
+    $menu = menu_get_menu();
+    foreach ($parents as $pid => $parent) {
+      // menu_get_menu() doesn't return the mid - which is what I need
+      // Grab it directly from the menu array.
+      if ($parent_menu_id = $menu['path index']['taxonomy/term/'. $pid]) {
+        $item['pid'] = $parent_menu_id;
+      }
+    }
+  }
+
+  $form['menu']['pid'] = array(
+    '#type' => 'select',
+    '#title' => t('Parent item'),
+    '#default_value' => $item['pid'],
+    '#options' => $options,
+  );
+
+  $form['menu']['path'] = array(
+    '#type' => 'hidden',
+    '#value' => $item['path'],
+  );
+
+  $form['menu']['weight'] = array(
+    '#type' => 'weight',
+    '#title' => t('Weight'),
+    '#default_value' => $item['weight'],
+    '#delta' => 10,
+  );
+
+  $form['menu']['mid'] = array(
+    '#type' => 'hidden',
+    '#value' => $item['mid'] ? $item['mid'] : 0,
+  );
+
+  $form['menu']['type'] = array(
+    '#type' => 'hidden',
+    '#value' => $item['type'] ? $item['type'] : MENU_CUSTOM_ITEM,
+  );
+}
+
+/**
+ * Adds the path alias edit function to term pages
+ * 
+ * Helper to edit_term_form_alter
+ * 
+ * extension under hook_form_alter().
+ */
+function edit_term_path_form($term, &$form) {
+  $system_path = 'taxonomy/term/'. $term->tid;
+  if ($term->tid) {
+    $path = drupal_get_path_alias('taxonomy/term/'. $term->tid);
+    if ($path == $system_path) {
+      // nah, forget it.
+      unset($path);
+    }
+  }
+  $form['path']['path'] = array(
+    '#type' => 'textfield',
+    '#title' => t('URL path settings'),
+    '#default_value' => $path,
+    '#access' => user_access('create url aliases'),
+    '#maxlength' => 250,
+    '#weight' => 3,
+  );
+  if ($path) {
+    $form['path']['pid'] = array(
+      '#type' => 'value',
+      '#value' => db_result(db_query("SELECT pid FROM {url_alias} WHERE dst = '%s'", $path))
+    );
+  }
+}
+
+/**
+ * Implementation of hook_taxonomy().
+ * 
+ * Capture the editing of a term from term edit form.
+ * Get the additional fields we added to the form. 
+ * Make out own updates as needed.
+ */
+function edit_term_taxonomy($op, $type, $form_values = NULL) {
+  if ($type == "term" && user_access('administer menu')) {
+    $term = (object) $form_values;
+    $termpath = 'taxonomy/term/'. $term->tid;
+    if ( ($gvid = variable_get('image_gallery_nav_vocabulary', '')) && ($term->vid == $gvid)) {
+      $termpath = 'image/tid/'. $term->tid;
+    }
+dpm($termpath);
+    switch ($op) {
+      case 'insert':
+      case 'update':
+        // If the checkbox is set, create/update a menu
+        // if not, remove it
+        if (! $term->menu['domenu']) {
+          menu_delete_item(array('path' => $term->menu['path']));
+          menu_rebuild();
+        }
+        else {
+          if (! $term->menu['title']) {
+            $term->menu['title'] = $term->name;
+          }
+          $term->menu['path'] = $termpath;
+          menu_edit_item_save($term->menu);
+          menu_rebuild();
+        }
+        // Also update term alias 
+        if (module_exists('path')) {
+          if ($term->path) {
+            path_set_alias($termpath, $term->path);
+          }
+          else {
+            path_set_alias($termpath);
+          }
+        }
+        break;
+
+      case 'delete':
+        menu_delete_item(array('path' => $termpath));
+        menu_rebuild();
+        if (module_exists('path')) {
+          path_set_alias($termpath);
+        }
+        break;
+    }
+  }
+}
+
+/**
+ * Self-documenting help page.
+ * Return my own page header
+ */
+function edit_term_about() {
+  // Render this file header as the readme available under admin/help
+  $chunks = preg_split( '/(@file)|(\*\/)/', file_get_contents(__FILE__) );
+  $readme = preg_replace('|\n\s*\*|', "\n", $chunks[1]);
+  $readme = preg_replace('|\n\s*@|', "\n<br/>\n@", $readme);
+  $readme = preg_replace('|\n\s*\n|', "\n<br/><br/>\n", $readme);
+  return $readme;
+}
