Overriding theme functions in a module

in

This seemingly trivial logical operation seems to be less than ideally implemented in Drupal. I am trying to instruct the menu system to display each item's description underneath the item text, in a smaller font. I located the theme_menu_item() function in menu.module that currently performs this task. What I want is to write my own theme_menu_item() that overrides this function by adding the item description on a new line. To achieve this the only way I could find was to start a new theme and put my override in template.php, that will get called by the drupal theme() function before the original theme_menu_item.

This is a waste of effort and duplication of theme code that is annoying! True, Drupal 6 should support theme inheritance, which will avoid the need for duplicating the theme code. However, that's not what I want! *Regardless* of the theme used, I still want to override that theme function! Ideally, a small module would provide that override and do nothing else.

The technical problem is that PHP does not allow one to unset() a function, which would have allowed me to simply unset menu.module's theme_menu_item() and use mine instead. No such luck. So it's up to Drupal to allow us to do that.

N.B. Without all the bells and whistles, my function would look like this:

function theme_menu_item($mid, $children = '', $leaf = TRUE) {
  $item = menu_get_item($mid);
  return '<li class="'. ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) .'">'. menu_item_link($mid) . $children .
         ($item['description'] ? '<span style="font-size: 80%">' . $item['description'] . '</span>' : '') .
         "</li>\n";
}