Hi,

It seems that weight in hook_menu aren't rendered in admin/index.

I took a look in system.admin.inc :

<?php
/**
 * Menu callback; prints a listing of admin tasks, organized by module.
 */
function system_admin_index() {
 
$module_info = system_get_info('module');
  foreach (
$module_info as $module => $info) {
   
$module_info[$module] = new stdClass();
   
$module_info[$module]->info = $info;
  }
 
uasort($module_info, 'system_sort_modules_by_info_name');
 
$menu_items = array();

  foreach (
$module_info as $module => $info) {
   
// Only display a section if there are any available tasks.
   
if ($admin_tasks = system_get_module_admin_tasks($module, $info->info)) {
     
// Sort links by title.
     
uasort($admin_tasks, 'drupal_sort_title');
     
// Move 'Configure permissions' links to the bottom of each section.
     
$permission_key = "admin/people/permissions#module-$module";
      if (isset(
$admin_tasks[$permission_key])) {
       
$permission_task = $admin_tasks[$permission_key];
        unset(
$admin_tasks[$permission_key]);
       
$admin_tasks[$permission_key] = $permission_task;
      }

     
$menu_items[$info->info['name']] = array($info->info['description'], $admin_tasks);
    }
  }
  return
theme('system_admin_index', array('menu_items' => $menu_items));
}
?>

The function "drupal_sort_weight" is not used for this page.
Moreover the Drupal 7 documentation for hook_menu says :

"weight": An integer that determines the relative position of items in the menu; higher-weighted items sink. Defaults to 0. Menu items with the same weight are ordered alphabetically.

So this function isn't implemented for admin/index page.
Is this wanted ?

Comments

longwave’s picture

It seems this page is ordered alphabetically by design. Ordering by weight doesn't necessarily make sense when items in one section may be combined from multiple parent menu items. Weight is only intended to be used when ordering under a single parent menu item.

Seyta’s picture

Well yeah I see.
I wanted to do that to "emphasize" some functionality in a module and put them at the top of the list.

I found a hack to bypass this by putting spaces in front of my titles so the design don't change and my menu are at the top of the section. kinda ugly solution =/. That's why I wanted to use weights to reorder my menu.

I don't understand when you say :

Ordering by weight doesn't necessarily make sense when items in one section may be combined from multiple parent menu items

In admin/index all menus that aren't "MENU_CALLBACKS" are grouped by modules. So how can they have multiple parents menu ?

longwave’s picture

Say your module provides four menu items:

/admin/structure/A - weight 0
/admin/structure/B - weight 5
/admin/config/C - weight -10
/admin/config/D - weight 10

In this case what I mean by "parent menu items" are /admin/structure and /admin/config. Imagine the weights are needed to correctly place them under the individual parents. If you also order /admin/index by weight then they would be listed C, A, B, D which may not necessarily make sense for many modules, especially if they provide large numbers of menu items - alphabetical seems to be the best compromise.

Seyta’s picture

HA !

I didn't think about that !

So now I understand why this "view" is only available in "alphabetical mode".
But I don't understand where weights are used then ... MENU_LOCAL_TASKS and Front Office and modules as administer_menu ?

Maybe this point should be explained somewhere in doc ? This thing drived me crazy thinking I wasn't using weights properly.