Drupal menu admin ‘admin/build/menu-customize’ with menu items collapsed

If you’re managing a lot of menu items it can get confusing (in the Drupal 6 interface at least) to see move things around. What would be good is if they were indented or collapsible. There’s a request for it floating about but it doesn’t seem to have generated that much interest. I’ve written a quick javascript solution for it which isn’t all that fast if you have lots of items, but it works for me. Something nicer is probably possible to do with the theme_menu_overview_form (modules/menu/menu.admin.inc), but I haven’t got the time at this point to investigate it further. See this thread http://drupal.org/node/521546#comment-4947478.

You need to add the javascript to your administration theme using the .info file, and substitute your theme name in the code where necessary.


Drupal.behaviors.sanbi_administration = function(context) {
$('#menu-overview tr').click( function() {
$indentationcount = $(this).find('.indentation').length;
if($(this).next().find('.indentation').length > $indentationcount) {
$show = false;
if($(this).hasClass('highlight'))
$show = true;

$(this).toggleClass('highlight');
recursiveHiding($(this).next(), $indentationcount, $show)
}
});

// Walk through table and hide rows which are more greatly indented than the row which was clicked
function recursiveHiding(element, $count, $show) {
if($(element).find('.indentation').length > $count) {
// Remove the highlight class for anything within the hierarchy
$(element).removeClass('highlight');
if($show)
$(element).show();
else
$(element).hide();
if($(element).next().length != 0)
recursiveHiding($(element).next(), $count, $show);
}
}
}

Because I am also adding a lot of custom javascript to certain pages for my administration theme, I actually included it only for the primary links menu like this:


/**
* Implementation of HOOK_preprocess_page().
*/
function mythemename_preprocess_page(&$vars) {
if (module_exists('path')) {
$path = drupal_get_path_alias($_GET['q']);
if($path == 'admin/build/menu-customize/primary-links') {
$vars['scripts'] .= '';
}
}

... Other stuff here...

Leave a Reply

Your email address will not be published. Required fields are marked *