From d89edb792e037fb49ae953f3c701a13d0211d580 Mon Sep 17 00:00:00 2001
From: Earl Miles <merlin@logrus.com>
Date: Tue, 31 Mar 2009 04:15:16 +0000
Subject: [PATCH] Clean up delegator task handler edit breadcrumbs so they are
 actually usable.

---
 delegator/delegator.admin.inc | 25 +++++++++++++++++++------
 delegator/delegator.module    | 21 ---------------------
 2 files changed, 19 insertions(+), 27 deletions(-)

diff --git a/delegator/delegator.admin.inc b/delegator/delegator.admin.inc
index acf71647..b9a42e01 100644
--- a/delegator/delegator.admin.inc
+++ b/delegator/delegator.admin.inc
@@ -40,15 +40,28 @@ function delegator_set_trail($task, $task_name = NULL) {
     return;
   }
 
+
   ctools_include('menu');
   $trail = menu_get_active_trail();
   $remove = ctools_get_menu_trail('admin/build/delegator');
-  foreach ($remove as $id => $info) {
-    if (isset($trail[$id])) {
-      unset($trail[$id]);
+  foreach ($remove as $info) {
+    foreach ($trail as $id => $crumb) {
+      if ($crumb['href'] == $info['href']) {
+        unset($trail[$id]);
+      }
     }
   }
 
+  if ($task_name) {
+    // Clean up broken 'Edit' link that Drupal leaves behind.
+    $trail = array_values($trail);
+    if (isset($trail[0]) && $trail[0]['title'] == t('Edit')) {
+      unset($trail[0]);
+    }
+
+    array_unshift($trail, menu_get_item('admin/build/delegator/' . $task_name));
+  }
+
   $trail = array_merge(ctools_get_menu_trail($task_type['admin path']), $trail);
   menu_set_active_trail($trail);
 }
@@ -1001,7 +1014,7 @@ function delegator_administer_task_handler_export($task_name, $name) {
   drupal_set_title(t('Export task handler "@title"', array('@title' => $title)));
 
   ctools_include('export');
-  delegator_set_trail($task);
+  delegator_set_trail($task, $task_name);
   return drupal_get_form('ctools_export_form', delegator_export_task_handler($handler), $title);
 }
 
@@ -1064,7 +1077,7 @@ function delegator_administer_task_handler_edit($task_name, $handler_id, $name,
   $title = delegator_get_handler_title($plugin, $handler, $task, $subtask_id);
   drupal_set_title(t('Edit task handler "@title"', array('@title' => $title)));
 
-  delegator_set_trail($task);
+  delegator_set_trail($task, $task_name);
   $form_state = array(
     'step' => $step,
     'task_name' => $task_name,
@@ -1250,7 +1263,7 @@ function delegator_administer_break_lock(&$form_state, $task_name) {
   $form = array();
 
   $task = delegator_get_task($task_id);
-  delegator_set_trail($task);
+  delegator_set_trail($task, $task_name);
 
   // @todo put task title here, but also needs subtask support.
   if (empty($lock)) {
diff --git a/delegator/delegator.module b/delegator/delegator.module
index 8ced9df4..5f26d5d9 100644
--- a/delegator/delegator.module
+++ b/delegator/delegator.module
@@ -76,27 +76,6 @@ function delegator_ctools_plugin_directory($module, $plugin) {
 function delegator_menu() {
   $items = array();
 
-  // Set up our own menu items here.
-  // @todo -- this is more or less deprecated now, but we need to change
-  // the import function so that it can import on a per task basis.
-/*
-  $items['admin/build/delegator'] = array(
-    'title' => 'Delegator',
-    'description' => 'Assign handlers to tasks such as node overrides',
-    'position' => 'right',
-    'page callback' => 'system_admin_menu_block_page',
-    'access arguments' => array('administer delegator'),
-    'file' => 'system.admin.inc',
-    'file path' => drupal_get_path('module', 'system'),
-  );
-
-  $items['admin/build/delegator/list'] = array(
-    'title' => 'Tasks',
-    'type' => MENU_DEFAULT_LOCAL_TASK,
-    'weight' => -10,
-  );
-*/
-
   // Task types get menu entries so they can set up their own administrative
   // areas.
   $task_types = delegator_get_task_types();
-- 
GitLab