1 menu.module _menu_get_menu_weight_delta($menu_names, $max_delta = NULL)

Calculate the delta for the weight element for a given set of menus.

Parameters

string|array $menu_names: Menu name or an array of menu names.

int $max_delta: Optional maximum value.

Return value

int: Delta value.

File

core/modules/menu/menu.module, line 700
Allows administrators to customize the site's menus.

Code

function _menu_get_menu_weight_delta($menu_names, $max_delta = NULL) {
  if (is_string($menu_names)) {
    $menu_names = array($menu_names);
  }

  $weight_info = db_query("SELECT MAX(weight) AS max_weight, MIN(weight) as min_weight FROM {menu_links} WHERE menu_name IN (:menu_names)", array(':menu_names' => $menu_names))->fetchObject();

  $delta = max(abs((int) $weight_info->min_weight), abs((int) $weight_info->max_weight)) + 1;

  // Honor max param, if given.
  if (!is_null($max_delta) && $delta > $max_delta) {
    $delta = $max_delta;
  }

  // Provide a minimum.
  if ($delta < 50) {
    $delta = 50;
  }
  return $delta;
}