You are here

function token_menu_link_load_all_parents in Token 7

Same name and namespace in other branches
  1. 8 token.module \token_menu_link_load_all_parents()
1 call to token_menu_link_load_all_parents()
token_tokens in ./token.tokens.inc
Implements hook_tokens().

File

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

Code

function token_menu_link_load_all_parents($mlid) {
  $cache =& drupal_static(__FUNCTION__, array());
  if (!is_numeric($mlid)) {
    return array();
  }
  if (!isset($cache[$mlid])) {
    $cache[$mlid] = array();
    $plid = db_query("SELECT plid FROM {menu_links} WHERE mlid = :mlid", array(
      ':mlid' => $mlid,
    ))
      ->fetchField();
    while ($plid && $plid != $mlid && ($parent = token_menu_link_load($plid))) {
      $cache[$mlid] = array(
        $plid => $parent['title'],
      ) + $cache[$mlid];
      $plid = $parent['plid'];
    }
  }
  return $cache[$mlid];
}