? context_reaction_menu_trail.patch
Index: context.core.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/context/Attic/context.core.inc,v
retrieving revision 1.1.2.3.2.20.2.29
diff -u -p -r1.1.2.3.2.20.2.29 context.core.inc
--- context.core.inc	5 Aug 2010 08:03:29 -0000	1.1.2.3.2.20.2.29
+++ context.core.inc	13 Aug 2010 22:37:39 -0000
@@ -298,6 +298,9 @@ function context_context_page_reaction()
   if ($plugin = context_get_plugin('reaction', 'breadcrumb')) {
     $plugin->execute();
   }
+  if ($plugin = context_get_plugin('reaction', 'menu_trail')) {
+    $plugin->execute();
+  }
   if ($plugin = context_get_plugin('reaction', 'css_injector')) {
     $plugin->execute();
   }
Index: context.plugins.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/context/Attic/context.plugins.inc,v
retrieving revision 1.1.2.8
diff -u -p -r1.1.2.8 context.plugins.inc
--- context.plugins.inc	30 Jul 2010 18:15:36 -0000	1.1.2.8
+++ context.plugins.inc	13 Aug 2010 22:37:39 -0000
@@ -88,10 +88,15 @@ function _context_context_registry() {
       'plugin' => 'context_reaction_breadcrumb',
     ),
     'menu' => array(
-      'title' => t('Menu'),
+      'title' => t('Menu class'),
       'description' => t('Control menu active class using context.'),
       'plugin' => 'context_reaction_menu',
     ),
+    'menu_trail' => array(
+      'title' => t('Menu trail'),
+      'description' => t('Set the current page to behave like a child of the selected menu item.'),
+      'plugin' => 'context_reaction_menu_trail',
+    ),
     'theme' => array(
       'title' => t('Theme'),
       'description' => t('Control theme variables using context.'),
@@ -268,6 +273,14 @@ function _context_context_plugins() {
       'parent' => 'context_reaction',
     ),
   );
+  $plugins['context_reaction_menu_trail'] = array(
+    'handler' => array(
+      'path' => drupal_get_path('module', 'context') .'/plugins',
+      'file' => 'context_reaction_menu_trail.inc',
+      'class' => 'context_reaction_menu_trail',
+      'parent' => 'context_reaction',
+    ),
+  );
   $plugins['context_reaction_theme'] = array(
     'handler' => array(
       'path' => drupal_get_path('module', 'context') .'/plugins',
Index: plugins/context_reaction_menu_trail.inc
===================================================================
RCS file: plugins/context_reaction_menu_trail.inc
diff -N plugins/context_reaction_menu_trail.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ plugins/context_reaction_menu_trail.inc	13 Aug 2010 22:37:39 -0000
@@ -0,0 +1,62 @@
+<?php
+// $Id: $
+
+/**
+ * Expose menu items as context reactions.
+ */
+class context_reaction_menu_trail extends context_reaction {
+  /**
+   * Provide a form element that allow the admin to chose a menu item.
+   */
+  function options_form($context) {
+    $menus = menu_trail_options(array_reverse(menu_get_menus()), NULL);
+    $root_menus = array();
+    foreach ($menus as $key => $name) {
+      $id = explode(':', $key);
+      if ($id[1] == '0') {
+        $root_menus[$id[0]] = check_plain($name);
+      }
+      else {
+        $link = menu_link_load($id[1]);
+        $identifier = $link['link_path'];
+        $root_menu = $root_menus[$id[0]];
+        while (isset($menus[$root_menu][$identifier])) {
+          $identifier .= "'";
+        }
+        $menus[$root_menu][$identifier] = $name;
+      }
+      unset($menus[$key]);
+    }
+    array_unshift($menus, "-- ". t('None') ." --");
+    return array(
+      '#title' => $this->title,
+      '#description' => $this->description,
+      '#options' => $menus,
+      '#type' => 'select',
+      '#default_value' => $this->fetch_from_context($context),
+    );
+  }
+
+  /**
+   * Override of options_form_submit().
+   * Trim any identifier padding for non-unique path menu items.
+   */
+  function options_form_submit($values) {
+    return trim($values, "'");
+  }
+
+  /**
+   * Set the menu item.
+   */
+  function execute() {
+    $item = menu_get_item();
+    $contexts = $this->get_contexts();
+    foreach ($contexts as $context) {
+      if (!empty($context->reactions[$this->plugin])) {
+        $item['href'] = $context->reactions[$this->plugin];
+        menu_set_item(NULL, $item);
+        break;
+      }
+    }
+  }
+}
