The Cheeky Monkey Media Blog

A few words from the apes, monkeys, and various primates that make up the Cheeky Monkey Super Squad.

Toolbar and Admin Menu Tweaks banner image

Have you ever been working on a site, and had your QA department or your client come back with issues because when logged in, the local tabs (view, edit, etc) distort the page layout? Or maybe there are a lot of pages that contain a lot of content, and it has become frustrating for site admins to have to scroll all the way back up to edit the page? Wouldn’t it be great to still have easy access to the local tabs and not have them add extra bulk to the page layout and content?

We have begun using a few different tweaks to add in the local tabs into the shortcuts menu area of a few of our main administration menu modules in Drupal. So far, we’ve added this to toolbar, admin_menu, and nav_bar.

The first step is to remove the rendering of the tabs in your page.tpl.php file(s). In most themes, you’ll find the following code renders out the tabs.


Simply delete or comment out those lines.

The second step is to add the local menu tabs and local actions to the shortcuts menu. All three modules have a preprocess or an alter hook to that allows us to add some extra menu items to the shortcuts menu area in each one. I’ll showcase the code we use for adding extras to admin_menu’s shortcuts area, but will also provide an example custom module which has examples for all three.

For admin_menu, we’ll take utilize hook_admin_menu_output_alter() to make our alterations.


function admin_menu_shortcuts_admin_menu_output_alter(&$build) {
 $path = drupal_get_path('module', 'admin_menu_shortcuts') . '/admin_menu_shortcuts.css';

 // Ensure our additions render last.
 $build['shortcut']['shortcuts']['toolbar'] = array(
    '#weight' => 99,
 $build['shortcut']['shortcuts']['toolbar']['menu_local_tabs'] = menu_local_tabs();
 $build['shortcut']['shortcuts']['toolbar']['menu_local_tabs']['#primary'][] = menu_local_actions();

 // Add workbench moderation menu if needed.
 if (module_exists('workbench_moderation')) {
   $build['shortcut']['shortcuts']['toolbar']['workbench'] = array(
     '#prefix' => '
‘, ‘button’ => array( ‘#prefix’ => ‘‘, ‘#markup’ => ‘Workbench information’, ‘#suffix’ => ‘‘, ), ‘content’ => workbench_block_view(), ‘#suffix’ => ‘

‘, ); } }


As you can see, there really isn’t much to it, once you know the structure you’re adding it to. However, with the Drupal admin_menu, just adding the alter function doesn’t get us all the way there. With admin_menu, there are two caching options which will nullify our new addition, since it will cache for one page, and won’t be contextual to the page you are on. However, if you set the following to variables to FALSE, admin_menu_cache_client and admin_menu_cache_server. This will disable the caching, and let your users enjoy the easier to use links.

And, as you’ve probably noticed, we have included a CSS file. In an effort to avoid conflicts with front-end and admin theme styling, we have created a custom overriding stylesheet to apply the module’s shortcuts menu styling to the new links to have a nice uniform look and feel everywhere across the site.

Another item to note is that our examples are using a module. Which means, the changes will apply to both front-end and admin themes. We realize that with admin themes, having the tabs show is more practical and useful, so not everyone will want the tabs in the shortcuts menu with both themes. We like to be consistent, so we use the module option most often, but you can also add all of these hooks to your custom theme’s template.php file to have them be front-end only.

Now, as promised, here is the full example module.