You are here

function _menu_get_menu_weight_delta in Drupal 7

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.

3 calls to _menu_get_menu_weight_delta()
menu_edit_item in modules/menu/menu.admin.inc
Menu callback; Build the menu link editing form.
menu_form_node_form_alter in modules/menu/menu.module
Implements hook_form_BASE_FORM_ID_alter().
menu_overview_form in modules/menu/menu.admin.inc
Form for editing an entire menu tree at once.

File

modules/menu/menu.module, line 654
Allows administrators to customize the site's navigation 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($weight_info->min_weight), abs($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;
}