Index: custom_breadcrumbs_panels/custom_breadcrumbs_panels.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/custom_breadcrumbs/custom_breadcrumbs_panels/Attic/custom_breadcrumbs_panels.module,v
retrieving revision 1.1.2.9
diff -u -p -r1.1.2.9 custom_breadcrumbs_panels.module
--- custom_breadcrumbs_panels/custom_breadcrumbs_panels.module	30 Dec 2010 18:36:25 -0000	1.1.2.9
+++ custom_breadcrumbs_panels/custom_breadcrumbs_panels.module	18 Feb 2011 18:15:51 -0000
@@ -102,7 +102,7 @@ function custom_breadcrumbs_panels_nodea
 /**
  * Implements hook_ctools_render_alter().
  */
-function custom_breadcrumbs_panels_ctools_render_alter($info, $page, $args, $contexts, $task, $subtask) {
+function custom_breadcrumbs_panels_ctools_render_alter($info, $page, $args, $contexts, $task, $subtask, $handler) {
   // Don't really do anything with the panel. This is just a pretense to insert a breadcrumb.
   static $module_weights = array();
 
@@ -127,7 +127,7 @@ function custom_breadcrumbs_panels_ctool
     }
   }
 
-  // Is this a taxonomy term template? 
+  // Is this a taxonomy term template?
   if (isset($task['admin path']) && ($task['admin path'] == "taxonomy/term/%term") && module_exists('custom_breadcrumbs_taxonomy') && variable_get('custom_breadcrumbs_taxonomy_panels', FALSE)) {
      module_load_include('inc', 'custom_breadcrumbs_taxonomy');
      foreach ($contexts as $context) {
@@ -143,8 +143,14 @@ function custom_breadcrumbs_panels_ctool
     global $language;
     $languages = array('language' => $language->language, 'all' => '');
     // Check to see if the panel ID matches any custom_breadcrumb panel_id.
-    $id = isset($subtask['name']) ? 'page-' . $subtask['name'] : $task['name'];
+    // First, try to find a match on panels variant ID:
+    $id = $handler->name;
     $breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_panels', NULL, array('panel_id' => $id), $languages);
+    // If nothing matched, try matching on panels page ID:
+    if (empty($breadcrumbs)) {
+      $id = $handler->task;
+      $breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_panels', NULL, array('panel_id' => $id), $languages);
+    }
     if (!empty($breadcrumbs)) {
       if ($breadcrumb = custom_breadcrumbs_select_breadcrumb($breadcrumbs, array('panel' => $info))) {
         custom_breadcrumbs_set_breadcrumb($breadcrumb, array('panel' => $info));
@@ -205,14 +211,31 @@ function custom_breadcrumbs_panels_form(
   $pages = array('operations' => array());
   page_manager_get_pages($tasks, $pages);
   foreach ($pages['rows'] as $id => $info) {
-    $options[$id] = $id;
+    // Build optgroups for pages with multiple variants. Show admin titles for
+    // pages & variants.
+    $task = page_manager_get_page_cache($id);
+    $title = decode_entities($task->subtask['admin title']);
+    if (count($task->handlers) > 1) {
+      $options[$title] = array(
+        $id => t('!title (All variants)', array('!title' => $title)),
+      );
+      foreach ($task->handlers as $handler) {
+        $options[$title][$handler->name] = decode_entities($handler->conf['title']);
+      }
+    }
+    else {
+      $handler = reset($task->handlers);
+      // The ID stored must be the ID of the variant, but we use the page admin
+      // title since this is often more helpful when there's only one variant.
+      $options[$handler->name] = $title;
+    }
   }
   $form['panel_id'] = array(
     '#type'          => 'select',
-    '#title'         => t('Custom Panel Page Id'),
+    '#title'         => t('Custom Panel Page'),
     '#required'      => TRUE,
     '#options'       => $options,
-    '#description'   => t('The Panel that this custom breadcrumb trail will apply to.'),
+    '#description'   => t('The Panel variant (or page) that this custom breadcrumb trail will apply to. If you want to apply the custom breadcrumb trail to all variants of a Panel page, choose the \'All variants\' option for that page.'),
     '#default_value' => isset($breadcrumb->panel_id) ? $breadcrumb->panel_id : NULL,
     '#weight'        => -10,
   );
