You are here

function menutrails_node_location in Menu TrailsMenu Trails 6

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

Determine the menu location of a node.

Inspired by _menu_get_active_trail().

4 calls to menutrails_node_location()
menutrails_comment in ./menutrails.module
This implements the same functionality as the nodeapi, but for comment urls.
menutrails_init in ./menutrails.module
Implementation of hook_init().
menutrails_nodeapi in ./menutrails.module
Implementation of hook_nodeapi().
menutrails_token_values in ./menutrails.module

File

./menutrails.module, line 125
Menutrails allows the assignment 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();
  $menu_name = variable_get('menutrails_menu', '');
  if (db_result(db_query("SELECT count(mlid) FROM {menu_links} WHERE link_path = '%s' AND module = 'menu' AND menu_name = '%s'", $item['href'], $menu_name)) == 0) {
    $type_trails = variable_get('menutrails_node_types', array());
    $href = $type_trails[$node->type] ? $type_trails[$node->type] : FALSE;
    $term_trails = variable_get('menutrails_terms', array());
    if (!empty($node->taxonomy)) {
      foreach ($node->taxonomy as $term) {
        if (!empty($term_trails[$term->tid])) {
          $href = $term_trails[$term->tid];
        }
      }
    }
  }
  else {

    // We may want to do some breadcrumbing.
    return $item;
  }

  // Organic groups support.
  if (module_exists('og') && !empty($node->og_groups)) {

    // We can only do one, so we take the first.
    $group = reset($node->og_groups);
    if (variable_get('menutrails_og_group_menu', FALSE) != FALSE) {
      if (db_result(db_query("SELECT count(mlid) FROM {menu_links} WHERE link_path = '%s'", $item['href'])) == 0) {
        $href = 'node/' . $group;
      }
    }
    else {
      $group_trails = variable_get('menutrails_og_node', FALSE);
      if ($group_trails[$group] > 0) {
        $href = 'node/' . $group;
      }
      elseif (variable_get('menutrails_og_post_default', FALSE)) {
        $href = variable_get('menutrails_og_post_default', FALSE);
      }
    }
  }
  if (!empty($href)) {
    $item['href'] = $href;
    return $item;
  }
  return FALSE;
}