You are here

function token_node_menu_link_load in Token 7

Load the preferred menu link associated with a node.

Parameters

$node: A node object.

Return value

A menu link array from token_menu_link_load() or FALSE if a menu link was not found.

See also

menu_node_prepare()

token_menu_link_load()

1 call to token_node_menu_link_load()
menu_tokens in ./token.tokens.inc
Implements hook_tokens() on behalf of menu.module.
1 string reference to 'token_node_menu_link_load'
token_clear_cache in ./token.module
Clear token caches and static variables.

File

./token.module, line 1275
Enhances the token API in core: adds a browseable UI, missing tokens, etc.

Code

function token_node_menu_link_load($node) {
  $cache =& drupal_static(__FUNCTION__, array());
  if (!isset($cache[$node->nid])) {
    $mlid = FALSE;

    // Nodes do not have their menu links loaded via menu_node_load().
    if (!isset($node->menu)) {

      // We need to clone the node as menu_node_prepare() may cause data loss.
      // @see http://drupal.org/node/1317926
      $menu_node = clone $node;
      menu_node_prepare($menu_node);
      $mlid = !empty($menu_node->menu['mlid']) ? $menu_node->menu['mlid'] : FALSE;
    }
    else {
      $mlid = !empty($node->menu['mlid']) ? $node->menu['mlid'] : FALSE;
    }
    $cache[$node->nid] = $mlid;
  }
  return $cache[$node->nid] ? token_menu_link_load($cache[$node->nid]) : FALSE;
}