menu_link_children_relative_depth

Versions
6 – 7
menu_link_children_relative_depth($item)

Find the depth of an item's children relative to its depth.

For example, if the item has a depth of 2, and the maximum of any child in the menu link tree is 5, the relative depth is 3.

Parameters

$item An array representing a menu link item.

Return value

The relative depth, or zero.

Related topics

▾ 3 functions call menu_link_children_relative_depth()

menu_link_save in drupal/includes/menu.inc
Save a menu link.
_book_parent_depth_limit in drupal/modules/book/book.module
Find the depth limit for items in the parent select.
_menu_parent_depth_limit in drupal/modules/menu/menu.module
Find the depth limit for items in the parent select.

Code

drupal/includes/menu.inc, line 2165

<?php
function menu_link_children_relative_depth($item) {
  $i = 1;
  $match = '';
  $args[] = $item['menu_name'];
  $p = 'p1';
  while ($i <= MENU_MAX_DEPTH && $item[$p]) {
    $match .= " AND $p = %d";
    $args[] = $item[$p];
    $p = 'p'. ++$i;
  }

  $max_depth = db_result(db_query_range("SELECT depth FROM {menu_links} WHERE menu_name = '%s'". $match ." ORDER BY depth DESC", $args, 0, 1));

  return ($max_depth > $item['depth']) ? $max_depth - $item['depth'] : 0;
}
?>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.