menu_link_children_relative_depth

  1. drupal
    1. 6
    2. 8
    3. 7
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 includes/menu.inc
Saves a menu link.
_book_parent_depth_limit in modules/book/book.module
Find the depth limit for items in the parent select.
_menu_parent_depth_limit in modules/menu/menu.module
Find the depth limit for items in the parent select.

Code

includes/menu.inc, line 3363

<?php
function menu_link_children_relative_depth($item) {
  $query = db_select('menu_links');
  $query->addField('menu_links', 'depth');
  $query->condition('menu_name', $item['menu_name']);
  $query->orderBy('depth', 'DESC');
  $query->range(0, 1);

  $i = 1;
  $p = 'p1';
  while ($i <= MENU_MAX_DEPTH && $item[$p]) {
    $query->condition($p, $item[$p]);
    $p = 'p' . ++$i;
  }

  $max_depth = $query->execute()->fetchField();

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