You are here

function ctools_menu_sort in Chaos Tool Suite (ctools) 7

Same name and namespace in other branches
  1. 6 includes/menu.inc \ctools_menu_sort()

Re-sort menu items after we have modified them.

1 string reference to 'ctools_menu_sort'
_ctools_menu_add_dynamic_items in includes/menu.inc

File

includes/menu.inc, line 44
General menu helper functions.

Code

function ctools_menu_sort($a, $b) {
  $a_weight = is_array($a) && isset($a['#link']['weight']) ? $a['#link']['weight'] : 0;
  $b_weight = is_array($b) && isset($b['#link']['weight']) ? $b['#link']['weight'] : 0;
  if ($a_weight == $b_weight) {
    $a_title = is_array($a) && isset($a['#link']['title']) ? $a['#link']['title'] : 0;
    $b_title = is_array($b) && isset($b['#link']['title']) ? $b['#link']['title'] : 0;
    if ($a_title == $b_title) {
      return 0;
    }
    return $a_title < $b_title ? -1 : 1;
  }
  return $a_weight < $b_weight ? -1 : 1;
}