Active Path

Component ID

1188110

Component name

Active Path

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Component created

Component changed

Component body

A helper module providing a function to be used in themeing or module building facilitating the detection of menu trails.

Description

There are several modules and suggestions for a path-based attribution of the "active" or "active-trail" class for links. Contrary to the substring-based method in e.g. Menu Trail By Path, this module first explodes pairs of pathes into arrays of arguments separated by "/" before it checks one against the other. Thus it avoids confusions resulting from partial word matchings like "grape => grapefruit". Finding an ordered intersection between current path alias and link path, it will attribute an "active" class to the latter. For example, a link pointing to "fruit/grape" will be flagged as active, if the current path is "fruit/grape/burgundy"; if the current path is "fruit/grapefruit" or "fruit/burgundy" it will be not. If the current path is an unaliased node path ('node/27'), there will be no effect at all. (For a content-based assignment of nodes to menu items, Menu trails does a good job.)

Usage

Note that this module does not do anything on its own. It just provides an alternative to the core l() function which is not a themeable function itself. In your template or module, you can override l() by active_path_l() where the normal active-class attribution is not working (which is often the case when views with placeholder arguments are used). The most interesting use case will be overriding theme_menu_item_link in template.php like this:

function MYTHEME_menu_item_link($link) {
  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
  }

  // If enabled, use Active Path module's alternative link function 
  if (module_exists('active_path')) {
    return active_path_l($link['title'], $link['href'], $link['localized_options']);
  } 
  else {
    return l($link['title'], $link['href'], $link['localized_options']);
  }
}