You are here

function menu_node_get_node in Menu Node API 7

Same name and namespace in other branches
  1. 6 menu_node.module \menu_node_get_node()

Get the relevant node object for a menu link.

This lookup function should be run for update and delete operations.

Parameters

int $mlid: The menu link id.

bool $load: TRUE (default) to return the full node object; FALSE to return only the node id.

bool $reset: TRUE to flush this node from the entity load cache before loading the node object; FALSE (default) to load from the cache.

Return value

A node id, a complete node object or FALSE on failure.

2 calls to menu_node_get_node()
menu_node_menu_link_update in ./menu_node.module
Implements hook_menu_link_update().
menu_node_record_delete_by_link in ./menu_node.module
Delete a record from {menu_node} by mlid and run hook_menu_node_record_delete().

File

./menu_node.module, line 106
Menu Node API Manages relationships between the {node} and {menu_links} table.

Code

function menu_node_get_node($mlid, $load = TRUE, $reset = FALSE) {
  $nid = db_query("SELECT n.nid FROM {node} n INNER JOIN {menu_node} mn ON n.nid = mn.nid WHERE mn.mlid = :mlid", array(
    ':mlid' => $mlid,
  ))
    ->fetchField();
  if (empty($nid)) {
    return FALSE;
  }
  if ($load) {
    if ($reset) {
      return entity_load_unchanged('node', $nid);
    }
    else {
      return node_load($nid);
    }
  }
  return $nid;
}