Skip to main content

September 17, 2015

CoffeeKeys: Enhancing the Coffee Module with a Custom Menu

Thought by Tim Green, Drupal Developer & QA Engineer

How many times a day do you mouse up to the “Content” link in the toolbar on your Drupal site? How about Views? Or to a specific admin page deep in the Drupal UI that you’re tired of navigating to with the mouse? If you’re like me, it’s a lot. In this post we’ll build a simple system to get you to those pages with just a couple keystrokes, using only the Coffee module and a custom menu.

About the Coffee Module

For those of you unfamiliar with the excellent Coffee module, it’s a quick access “shortcut key” tool that takes you to any menu item within the Drupal admin section. Just hit “Option-d” from anywhere in Drupal, and Coffee brings up a modal input field. Start typing the name of, or path to, anywhere you want to go within the Drupal admin system, and Coffee will narrow your choices as you type.

If your destination is the first one on the list, you can simply hit “Return” and you’ll be taken to that page. Or you can use the arrow keys (and hit Return) or click an item with the mouse to choose any destination in the list.

It’s very convenient, and indispensable once you’ve used it for a while. The Coffee module has become part of my standard Drupal installation. And it’s so easy to use. The only configuration options for the module are the standard Permissions settings, and which menus it should reference. Remember, Coffee only recognizes menu items in the standard Drupal menu system, but the great thing is that it also recognizes custom menus that you create! And you create them for your navigation convenience. Here’s why, and how:

As good as Coffee is right out of the box, what if we, for example, need to get to a specific Views edit page... one that has a path like this: admin/structure/views/view/admin_views_node/edit? And what if we find ourselves editing that View often and we want a shortcut to it? Well, we can’t do it with Coffee (yet) because there isn’t an existing menu item in the Drupal admin system to go directly to that page, which means Coffee is unaware of it.

So what we’re going to do in this post is enhance the Coffee module by creating links in a custom menu that Coffee will monitor. Then when we use Coffee, those links will appear in its results. And by using clever link titles, we can create one or two-character shortcuts to go to any page on the site with very little effort. I call these “CoffeeKeys.” Keep in mind that this isn’t an official Drupal term, and is not technically associated with the Coffee module. I just call them that for fun.

Enhancing Coffee with “CoffeeKeys”

Step 1: Download and install the Coffee module.

Step 2: Create a new menu at /admin/structure/menu/add and give it any name you want. I always name mine “CoffeeKeys menu.”

Step 3: Go to the Coffee configuration page at /admin/config/user-interface/coffee (or just hit Option-d and type “ff” for the fastest way to get there) then check the box next to your menu (and any others you want to use with Coffee) and click “Save configuration.”

This is important! By default, Coffee only monitors the Management and User menus, but you can add any menu to its watch list. This tells Coffee you want it to include that menu’s links in its results. If you forget this step you won’t see your shortcuts when you use Coffee.

Step 4: Think of a page you’ve been going to a lot recently, let’s say Views, which you visit often during site building. In the next step we’ll assign a shortcut to get you there instantly. We’ll use the number 3 to begin the link title.

This will make Coffee show it first when you hit “Option-d-3” since there are usually no other admin menu items with numbers in them, and remember, it searches links and link titles from left to right. I always use the keys on the left side of the keyboard, near the “d” key, like the numbers 1 to 5, or the letters q, s, x, etc., so I can do it all with my left hand and click the mouse or hit Return with my right. By the way, if you change your mind and want to dismiss the Coffee input field, just hit the “Escape” key at any time and it will dismiss.

Step 5: Now create a link to the Views page in the CoffeeKeys menu so it will be exposed to Coffee. I usually put the CoffeeKeys menu on the Dashboard so I can get to it easily, but you don’t have to put the menu on your site at all for Coffee to see it, it just needs to exist. And to get to the Dashboard configuration page using Coffee, simply hit “Option-d-da” and then Return. You can also put the CoffeeKeys menu in the header or sidebar of your front-facing theme, at least while you’re working on it, for even faster access.

You can see in the example below that I added a link to views (admin/structure/views) in the CoffeeKeys menu, and gave it a link title of “3-Views” so we can hit “Option-d-3” to bring it up first. In this example I’ve created some additional shortcut keys for pages that are tricky to get to because they’re buried deep in the Drupal system.

The idea here is to recognize the places you go to most often and create a shortcut link in your CoffeeKeys menu to get you there fast. Note that sometimes a single letter or number will bring up a destination other than the one you want, so I often use two keys in a row, like “aa” or “qq,” and since those letters rarely appear together, my choice will always be at the top and I can simply hit Return to go there.

One of my favorite ways to use CoffeeKeys is to get to the “Manage fields” pages of content types I’m working on, since they’re somewhat tedious to get to. In the example above, the CoffeeKey to edit the “Basic page” fields is “Option-d-bb.”

Another neat trick is to make the CoffeeKeys menu page one of your shortcuts. That way you can add your favorites even faster. Try “Option-d-qq” for this tip if you want to.

You can even use a CoffeeKey to get to the edit page of a node that you need to visit often. This saves a lot of time because you don’t have to find it on the site or go to the Content page and search for it. Just add a link in your CoffeeKeys menu and off you go.

I like to provide my content managers with custom links on the dashboard for pages they visit often, but now you can use CoffeeKeys to give them shortcuts, to get to those pages even faster. They’ll love you for it.

Step 6: Add your favorite and most-visited pages to the CoffeeKeys menu, and if you forget what your shortcuts are you can always go to the Dashboard and look at your CoffeeKeys menu for a refresher. That’s all there is to it. Sweeten to taste and enjoy!

If you need more Drupal how-tos, be sure to check back with our training page often.

(Special thanks to michaelmol at Drupal.org for creating and maintaining the Coffee module.)