You are here

function power_menu_node_location in Power Menu 6

Same name and namespace in other branches
  1. 7 power_menu.module \power_menu_node_location()

Determine the menu location of a node.

Inspired by _menu_get_active_trail().

3 calls to power_menu_node_location()
power_menu_block in ./power_menu.module
implementation of hook_block().
power_menu_nodeapi in ./power_menu.module
implementation of hook_nodeapi().
power_menu_preprocess_page in ./power_menu.module
Implementation of hook_preproces_page().

File

./power_menu.module, line 285
This module provides some additional menu features. The features are not actually new, but are part of other modules. it's though very cumbersome to creating a new menu item, because one has to go to all the different places to configure these…

Code

function power_menu_node_location($node) {

  // This should only fire if the menu isn't already active.
  $item = menu_get_item();
  $current_power_menu = power_menu_get_menu();

  // incase the node is directly somewhere in the navigation we don't need all the checking
  // and just use the core handling to decide which menu item to mark active
  $mlid = db_result(db_query("SELECT mlid FROM {menu_links} WHERE menu_name='%s' AND link_path='%s'", array(
    $current_power_menu,
    "node/{$node->nid}",
  )));
  if ($mlid > 0) {
    return NULL;
  }

  // check if this nodetype is assigned to some menu path
  if (($href = db_result(db_query("SELECT path FROM {power_menu} WHERE nodetype='%s' AND menu_name = '%s'", array(
    $node->type,
    $current_power_menu,
  )))) != '') {
    $item['href'] = $href;
    return $item;
  }

  // we are going to check if there are certain taxonomy terms that should active a menu item
  $ar_tid = array();
  if (!empty($node->taxonomy)) {
    $href = _power_menu_get_node_location_taxonomy($node, $current_power_menu);
    if ($href) {
      $item['href'] = $href;
    }
    return $item;
  }
  return NULL;
}