Context Module allows for setting a primary or secondary link active when certain conditions are met (i.e certain node types are being viewed). The Context Module adds an "active" class to the selected menu <li> that is not showing up in Fusion based themes due the Fusion Core preprocess page function and how Superfish is implemented. By checking <?php print theme('links', $primary_links); ?>, the proper Context functionality is observed, while with <?php print theme('grid_block', $primary_links_tree, 'primary-menu'); ?>, it is not. However, without the latter, Superfish doesn't work. To observe the difference, take a look at both print statements side by side in firebug and note the classes. I think it is important to get Fusion Core compatible with the Context Module due to it's huge potential and growing adaptation. I'll continue to post any progress.

Comments

brentratliff’s picture

UPDATED

Works for case when Primary Menu dropdown is disabled according to function fusion_core_preprocess_page(&$vars)

else 
      $vars['primary_links_tree'] = theme('links', $vars['primary_links'], array('class' => 'menu'));

It has different class assignments but easily selectable with css. The problem with Superfish is the replacement of classes in

$vars['primary_links_tree'] = preg_replace('/<ul class="menu/i', '<ul class="menu sf-menu', $vars['primary_links_tree'], 1);

Somehow the active class needs to be left in when the string is replaced if dropdown menus are selected in theme settings.

brentratliff’s picture

Possibly some logic in:

function fusion_core_grid_block($element, $name) {
  $output = '';
  if ($element) {
    $output .= '<div id="' . $name . '" class="' . $name . ' block">' . "\n";
    $output .= '<div id="' . $name . '-inner" class="' . $name . '-inner inner clearfix">' . "\n";
    $output .= $element;
    $output .= '</div><!-- /' . $name . '-inner -->' . "\n";
    $output .= '</div><!-- /' . $name . ' -->' . "\n";
  }
  return $output;
}

, to check for the 'active' string in $element and leave it alone?

brentratliff’s picture

This can be done in a module using function hook_menu_link_alter(&$item, $menu) but I'm still hoping to handle it in the theme layer so all Fusion themes can use it. Thoughts?

brentratliff’s picture

Currently using jQuery for this functionality by selecting a class added with the Menu Attributes module. I may visit this later to get the functionality in Fusion Core without Javascript.

martysteer’s picture

The fusion template preprocess logic which builds the $primary_links_tree var for the superfish scripts also strips out any CSS menu id's. I think the Menu API in Drupal is doing this.

sociotech’s picture

brentratliff,

This appears to be a functionality gap. In order to create a Superfish dropdown menu, we have to use a a menu tree structure, but (according to #586396: Context Active menu problem) Context module only adds its active class to standard primary and secondary menus, not menu tree structures.

So this is probably a problem for any combination of Context and a theme or module that creates dropdown menus. Though if you know of a generic dropdown menu solution that works with Context I'd be eager to hear about it.

The issue above includes several possible fixes, but I'd really like to avoid adding module-specific code to Fusion. From experience, it usually ends up creating more issues for users than it fixes.

Ideally, the solution would be for Context module to add its classes to menu tree structures as well, but that's an issue for its developers to consider.

In the meantime, perhaps you could post your JQuery solution here for others who are having this problem.

In conclusion, I'm open to suggestions for solutions to this issue that don't involve adding module-specific code to Fusion, but I don't otherwise see that there's much we can do to fix the problem at our end.

brentratliff’s picture

Sociotech,

Thanks for looking into this issue. I agree that you don't want to go down the road of adding unique fixes based on contrib modules. There seems to be a code snippet in http://drupal.org/node/586396 that is working for some. This is the jQuery solution I used:

I added a class to each primary link menu item with http://drupal.org/project/menu_attributes.
For each logical section in which I wanted the active class, I added the following snippet to the appropriate template file: (views, node, etc)

//highlights events primary menu item via css when template is used
drupal_add_js (
    '$(document).ready(function(){$("#eventmenu").addClass("active");}); ',
    'inline');

#eventmenu is the id added with the menu attributes module. It will need to be changed for each logical section (primary link item in my case). It's not ideal but works great. Google Analytics shows almost all my visitors have javascript enabled. Hopefully it will help someone.

sociotech’s picture

brentratliff,

Thanks very much for posting your JQuery-based solution.

I'd also be interested to hear if anyone has tried to fix the issue by adding this snippet from the Context issue you referenced to a template.php file in their Fusion subtheme: http://drupal.org/node/586396#comment-2608608

The only thing I can see that should be modified in that snippet is to change the function name from phptemplate_menu_item() to SUBTHEMENAME_menu_item(), where SUBTHEMENAME is the name of your subtheme (e.g., acquia_prosper).

While I don't think it would be a good idea to add something this module-specific to Fusion Core, it would be helpful to know if it's a reliable fix that could be dropped in on an as-needed basis.

Thanks.

wigglykoala’s picture

I'm having this issue with 6.x-1.0 I tried http://drupal.org/node/586396#comment-2608608 but no luck. I'm not using spaces which seems to be causing the problem as I am getting a fatal error

Fatal error: Call to undefined function spaces_get_space()

Think I will have to try the jQuery way next as my PHP isn't good at all!!

wigglykoala’s picture

removed

$space = spaces_get_space();
    $purl = $space->purl.'/';
    if (
      // Check against both the path, and path without PURL
      in_array($link_path, $active_paths) ||
      (isset($space->purl) && in_array(str_replace($purl, '', $link_path), $active_paths))
    ) {
      $class .= ' active-trail';
    }

and now I get "warning: Invalid argument supplied for foreach() in.... /sites/all/themes/fusion/fusion_core/template.php on line 541."

I am pasting this is into fusion core which I know isnt best practise, but I just want to get it to work before doing anything else!

hedac’s picture

has anyone fixed this context compatibility with Fusion superfish menus?
subscribing

BlueBlossom’s picture

subscribing

malapeiro’s picture

hi, dont know how to code, but i solve this issue with menu position module (https://drupal.org/project/menu_position) instead of context module. it works for me!

Poieo’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Closed as won't fix since the D6 version is no longer supported.