How to sort owner menu?


I want to sort the owner menu. The default is alphabetically. But I want to use the priority value.

That my try, which is not working (priority is ignored - always sorted alphabetically by text value)

elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'tobi_owner_block_menu',1000);

function tobi_owner_block_menu($hook, $type, $return, $params) {
     if (elgg_instanceof($params['entity'], 'user')) {    
      //unset the old ones
      $return= array();
            $options = array(
              'name' => 'agvideoUserVideo',
              'text' => elgg_echo('votw_video:videoList').' - '.$params['entity']->name,
              'href' => 'agvideo/owner/'.$params['entity']->username,
              'priority' => 50,
            $return[] = ElggMenuItem::factory($options);
            $options = array(
              'name' => 'agvideoFansOf',
              'text' => elgg_echo('votw_video:fans'),
              'href' => 'friendsof/'.$params['entity']->username,
              'priority' => 100,
            $return[] = ElggMenuItem::factory($options);

      $options = array(
              'name' => 'file',
              'text' => elgg_echo('votw_video:pictures');,
              'href' => 'file/owner/'.$params['entity']->username,
              'priority' => 100,
      $return[] = ElggMenuItem::factory($options);
      $options = array(
              'name' => 'blog',
              'text' => elgg_echo('votw_video:blogs');,
              'href' => 'blog/owner/'.$params['entity']->username,
              'priority' => 150,
     $return[] = ElggMenuItem::factory($options);

   return $return;



  • Seems this does not work with setPriority().  However, the following 2 documented methods of ElggMenuItem are doing the same:

         setWeight ($priority)
         Set the priority of the menu item.

         setPriority ($priority)
         Set the priority of the menu item

    So what on earth is the difference? :-)

    Have you tried with setWeight()? this might work.

  • The priority is part of the EllgMenuItem, but it is not sorted by it.

    Now I have done it this way.

    I have copied the view "views/default/navigation/menu/default.php" to my plugin under


    Then I added this function to the code to sort the menuitems by priority

    function sortOwnerMenu($a, $b)
        if(is_object($a) AND is_object($b)){
          if ($a->getPriority() == $b->getPriority()) {
            return 0;
          return ($a->getPriority() < $b->getPriority()) ? -1 : 1;

    usort($vars['menu']['default'], 'sortOwnerMenu');

    This works - but perhaps there is a more "elgg-like" way to do this?

  • The sort is done during the ElggMenuBuilder::getMenu call:

    I don't know offhand if there's a way to set this dynamically, but if so, that would be the most elgg-like way I guess.