You are here

function _menu_link_weight_reorder_options in Menu Link Weight 8

Same name and namespace in other branches
  1. 8.2 menu_link_weight.reorder.inc \_menu_link_weight_reorder_options()
  2. 7 menu_link_weight.reorder.inc \_menu_link_weight_reorder_options()

Allow other modules to reorder the tree.

This will insert the current item under/above a specified other item, or on top of the list.

Parameters

array $options: List of options, with index "link_current" or the menu link ID.

string $relative_position: Where to insert the current item. Either "top", "above_{mlid}" or "below_{mlid}".

Return value

array Reordered array of options.

2 calls to _menu_link_weight_reorder_options()
menu_link_weight_menu_link_content_element_process in ./menu_link_weight.menu_ui.inc
Process callback for the menu link weight element.
menu_link_weight_node_element_process in ./menu_link_weight.node.inc
Process callback for the menu link weight element.

File

./menu_link_weight.reorder.inc, line 22
Functionality related to reordering of options by other modules.

Code

function _menu_link_weight_reorder_options(array $options, $relative_position) {
  $weight = MENU_LINK_WEIGHT_MIN_DELTA;
  $reordered_options = array();
  if (isset($options['link_current'])) {
    $link_current = $options['link_current'];
    unset($options['link_current']);
  }
  else {

    // Return original options.
    return $options;
  }

  // If the "relative position" is to be "top", insert the current link all the
  // way on top of the list.
  if ($relative_position == 'top') {
    _menu_link_weight_insert_item($reordered_options, 'link_current', $link_current, $weight);
  }
  foreach ($options as $id => $option) {

    // If the relative position is to be "above_{mlid}", insert the current link
    // just above the item with the given menu link ID.
    if ($relative_position == 'above_' . $id) {
      _menu_link_weight_insert_item($reordered_options, 'link_current', $link_current, $weight);
    }

    // Insert the regular items.
    _menu_link_weight_insert_item($reordered_options, $id, $options[$id], $weight);

    // If the relative position is to be "above_{mlid}", insert the current link
    // just below the item with the given menu link ID.
    if ($relative_position == 'below_' . $id) {
      _menu_link_weight_insert_item($reordered_options, 'link_current', $link_current, $weight);
    }
  }
  return $reordered_options;
}