You are here

function menutrails_node_location in Menu TrailsMenu Trails 5

Same name and namespace in other branches
  1. 6 menutrails.module \menutrails_node_location()

Determine the menu location of a node.

Inspired by _menu_get_active_trail().

2 calls to menutrails_node_location()
menutrails_comment in ./menutrails.module
This implements the same functionality as the nodeapi, but for comment urls.
menutrails_nodeapi in ./menutrails.module

File

./menutrails.module, line 53
Menutrails allows the assigment of "trails" which will keep menu items active for individual node views.

Code

function menutrails_node_location($node) {

  // This should only fire if the menu isn't already active.
  $item = menu_get_item(NULL, 'node/' . $node->nid);

  // type = 4 is for a callback
  if ($item['type'] == 4) {
    $type_trails = variable_get('menutrails_node_types', array());
    $mid = $type_trails[$node->type];
    $term_trails = variable_get('menutrails_terms', array());
    if (isset($node->taxonomy)) {
      foreach ($node->taxonomy as $tid => $term) {
        if ($term_trails[$tid] > 0) {
          $mid = $term_trails[$tid];
        }
      }
    }
    if ($mid > 0) {

      // Follow the parents up the chain to get the trail.
      while ($mid && ($item = menu_get_item($mid))) {
        $location[] = $item;
        $mid = $mid = $item['pid'];
      }
      $location = array_reverse($location);
      $location[] = array(
        'path' => 'node/' . $node->nid,
        'title' => $node->title,
      );
    }
    return $location;
  }
}