function power_menu_node_location in Power Menu 7
Same name and namespace in other branches
- 6 power_menu.module \power_menu_node_location()
Determine the menu location of a node.
Inspired by _menu_get_active_trail().
2 calls to power_menu_node_location()
- power_menu_node_view in ./
power_menu.module - Implements hook_node_view().
- power_menu_preprocess_page in ./
power_menu.module - Implements hook_preproces_page().
File
- ./
power_menu.module, line 310 - 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) {
$item = menu_get_item();
// Check is path recognition enabled for this content type
$path_ct = variable_get('power_menu_path_content_types', array());
if (in_array($node->type, $path_ct, TRUE)) {
// Get the path alias and remove the last path element
$alias = drupal_lookup_path('alias', "node/" . $node->nid);
$alias = explode('/', $alias);
array_pop($alias);
// Does a parent path exists
if (count($alias) > 0) {
$alias = implode('/', $alias);
// Menu link lookup for given alias
$link_path = db_query("SELECT ml.link_path FROM url_alias AS ua LEFT JOIN menu_links AS ml ON ua.source = ml.link_path WHERE ua.alias = :alias", array(
':alias' => $alias,
))
->fetchField();
if ($link_path) {
$item['href'] = $link_path;
return $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_query("SELECT mlid FROM {menu_links} WHERE menu_name = :menu_name AND link_path = :link_path", array(
':menu_name' => $current_power_menu,
':link_path' => "node/{$node->nid}",
))
->fetchField();
if ($mlid > 0) {
$item = NULL;
}
// check if this nodetype is assigned to some menu path
if (($href = db_query("SELECT path FROM {power_menu} WHERE nodetype = :nodetype AND menu_name = :menu_name", array(
':nodetype' => $node->type,
':menu_name' => $current_power_menu,
))
->fetchField()) != '') {
$item['href'] = $href;
}
// we are going to check if there are certain taxonomy terms that should active a menu item
$taxonomy_field = 'field_' . variable_get('power_menu_taxonomy_field', '');
if (!empty($taxonomy_field) && !empty($node->{$taxonomy_field})) {
$href = _power_menu_get_node_location_taxonomy($node, $current_power_menu);
if ($href) {
$item['href'] = $href;
}
}
return $item;
}