Hey there,

Please override theme_link instead of theme_menu_link.

(Sorry, way too busy for a patch)
context.module (lines #181 ~ #199)

/**
 * Implementation of hook_preprocess_link().
 *
 * This allows menus that are not primary/secondary menus to get
 * the "active" class assigned to them. This assumes they are using
 * theme('link') for the menu rendering to html.
 */
function context_preprocess_link(&$variables) {
  if($contexts = context_active_contexts()){
    foreach($contexts as $context){
      if((isset($context->reactions['menu']))){
        if ($variables['path'] == $context->reactions['menu']) {
          $variables['options']['attributes']['class'][] = "active";
        }
      }
    }
  }
}

Same thing helped Special Menu Items module to be compatible with other modules: #1447988: Override theme_link instead of the theme_menu_link

Thanks!

Comments

mehrpadin’s picture

PS: You may need to clear the cache in order to see the results of the new hook_preprocess.

tekante’s picture

Can you provide some information as to which modules this helps with? From the other referenced issue it appears superfish may be one but this appears to open up context menu reactions to manipulating the class attribute on any link rather than just those acting as menu items.

mehrpadin’s picture

I don't know, Toolbar for example? you're right, affects non-menu links as well, makes things complicated, however thinking more I guess it's not that bad you can let the user choose; for example a checkbox saying "Also extend this reaction to any link with the same path as the selected menu item.", hopefully checked by default, lol, or even maybe a whole new reaction! Links! there are many many links now that I'm thinking about it that deserve reactions and are simply not menu links, maybe Context should go with both, the checkbox and the Links reaction! what do you think?

tekante’s picture

Category: bug » feature

The idea of making it a separate reaction seems most correct at first glance as I think it would be unintuitive to have the option for adding classes to any link under the menu reaction. I could also see a desire to control what classes are added instead of just having "active" be implied. This might also be best as a separate module providing the plugin reaction rather than trying to roll it in the core module. I'm going to mark this as a feature request since I believe the current functionality operates as intended and let others comment here to help judge the desire of having this as part of core context functionality.

davethebrave’s picture

I have a problem where my superfish menu is not displaying in my contexts. Will this code change solve that problem?

I'm using the latest Drupal (7.20), Context 7.x-3.0-beta6 and I installed context menu block. I'm new to both superfish and context, as you can probably guess.

mehrpadin’s picture

Dave,
I've kinda fixed it, in a not-so-professional way though, will soon update the development release.

mehrpadin’s picture

Issue summary: View changes

Removed a blank line :)