1 menu.tokens.inc _menu_token_node_link_load(Node $node)

Load the preferred menu link associated with a node.

Parameters

Node $node: A node object for which a menu link should be loaded.

Return value

array|FALSE: A menu link array from _menu_token_link_load() or FALSE if a menu link was not found.

See also

menu_node_prepare()

_menu_token_link_load()

File

core/modules/menu/menu.tokens.inc, line 267
Builds placeholder replacement tokens for menu-related data.

Code

function _menu_token_node_link_load(Node $node) {
  $cache = &backdrop_static(__FUNCTION__, array());

  if (!isset($cache[$node->nid])) {
    // 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] ? _menu_token_link_load($cache[$node->nid]) : FALSE;
}