Hi, using 7.x-2.x-dev and Context UI. Using the Context module to set an "active menu", but the nicemenus does not get the 'active-trail' class (or any active CSS class).

Is there a solution?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

They're trying to solve this on the Context UI side,
#586396: Context Active menu problem

Anonymous’s picture

Solution: in nice_menus.module, inside theme_nice_menus_build()

      $context_active = FALSE;
      if (module_exists('context')) {
        if ($contexts = context_active_contexts()){
          foreach ($contexts as $context){
            if (isset($context->reactions['menu'])) {
              if ($menu_item['link']['link_path'] == $context->reactions['menu']) {
                $context_active = TRUE;
              }   
            }   
          }   
        }
      }    
      
      if (($trail && in_array($mlid, $trail)) || $context_active) {
        $class .= ' active-trail';
      }
altrugon’s picture

Taking the solution mentioned on comment #2 as a guide I have created a patch that not only set the class "active-trail" but also the class "active" for the link.

This patch has been created from the master branch that is the recommended release 7.x-2.0.

altrugon’s picture

Status: Active » Needs review
altrugon’s picture

Classic, I upload the patch and then apply it from here and it doesn't work.

Second try, and this one solves a problem with undefined index that the previous patch had.

BarisW’s picture

Status: Needs review » Reviewed & tested by the community

Cool. Patch works great. Thanks!

Anonymous’s picture

#5 worked for me!

vordude’s picture

Status: Reviewed & tested by the community » Needs work

I'm inclined to think we could be better off in adding an active class where one belongs instead of creating specific code that works with 1 other specific contributed module? (albeit a popular one)

DuaelFr’s picture

Status: Needs work » Needs review
FileSize
2.1 KB

@vordude I agree but waiting for the better solution, this one works ;)

@altrugon Your patch does not seems to activate selected menu parents. Here is a new improved patch based on yours.

osopolar’s picture

Maybe this fixes this issue: #835090: Context Reaction: Set menu trail

altrugon’s picture

Version: 7.x-2.x-dev » 7.x-2.1
FileSize
1.52 KB

I can't believe this hasn't been fixed yet, my last post was submitted in 2011 and neither Nice Menu or Context have solved it yet :(

Anyhow here goes another patch against Nice Menu 7.x-2.1 that is the stable release at this moment.

xiukun.zhou’s picture

Status: Needs review » Fixed

Thanks a lot to altrugon, DuaelFr, morningtime and everyone else for the great work on the patches, testing, reviews and reporting.

It's more time this got committed and I went ahead and had this rolled at: 7.x-2.x: 6969cde.

Marking this as fixed.

Please let me know if you would have any other questions, comments, issues or concerns on any of these changes, I would be glad to provide more information.
Thanks again to everyne for the help and great work on this issue.

Cheers!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.