Quickly access configuration of blocks, menus and more. A new design pattern in Drupal 7.
The concept
Drupal provides little context, when performing administrative tasks. You easily lose context of what you are working on, when you administer your site. Contextual links tries to reverse this by providing links to the administration features from the actual context, e.g. block or content.
We saw this pattern emerge in two popular community projects; Views and Zen. Both expose links to quickly access configuration. Understanding how it was used in the real world helped us shape the pattern we have in Drupal 7 now.
Designing it
Designing this interaction was about exploring known interaction models and adapting these to Drupal’s environment. Since Contextual Links were introduced very late in the development cycle, we had to be sure that the interaction model had already proven itself in the wild.

Roy Scholten designed the initial prototype. We found that showing the contextual action upon hover, and the actual links upon click, was least distracting.
Given that initial direction, the community pointed out several design constraints:
- Likely up to 6 links per context.
- No icons, as we don't know the actual link tasks.
- Links can appear on everything, everywhere, so don’t distract.
With those constraints we continued iterating and ended with two final prototypes, a vertically stacked and a horizontally stacked. During testing of both interactions, we found a major drawback of the horizontally stacked one: with more than two menu items it tends to lose its scan-ability.
The icon was a relatively easy choice, as we knew that these links where mostly about "configuration". It wasn't much of an "edit" action where a pen would suffice - therefore the cog was chosen.
Outline
To hint at which “object” a particular set of contextual links are related to, an outline appears to provide orientation. Designing this turned out to be an interesting challenge, as contextual links can appear very closely to each other. By only showing the outline upon hovering the icon, the orientation is kept intact.
State transition
Something we rarely do in Drupal, is state transitions. Which means to provide a state glue between the initial visual state and the final visual state of an element. Such small “animations” make Drupal feel more smooth and better, because it provides feedback on what is going on.

The contextual menu opens step-by-step in just a few milliseconds.
Recommendations using it
Themes
The styling of contextual links is fairly generic – they use a sensible default for themes to customize. Themes are encouraged to change details to better fit to the visual style of the theme. Especially darker themes might see a need to change the outline and backgrounds.
Modules
Modules have a great opportunity to bring configuration closer to the context. Contextual links should ideally be used by modules that expose extra configuration for an “element” (block, menu, node, anything). Views is a good example, as it exposes a link to “Edit view”.
However, make sure that only important and frequently used functionality is exposed in contextual links, to prevent them from getting overloaded with infrequently used actions:
- Use a short, descriptive link title. (2-3 words).
- Keep the action word at the beginning. (e.g. edit, delete, list).
- Avoid similar labels such as Edit menu and Edit menu links.
- Avoid more then 6 tasks.
Thanks to David Rothstein, Gábor Hojtsy, tha_sun, Charlie Gordon, seutje, catch, Roy Scholten and many more for working on this.
Discussion
For those wondering how to add contextual links, when defining a local task (or "tab" for humans), settings the context array key to the constant
MENU_CONTEXT_INLINEwill make it appear as a contextual link, see http://api.drupal.org/api/function/hook_menu/7 (like 2/3 down the page) or for a concrete example, see http://api.drupal.org/api/function/node_menu/7 where $items['node/%node/edit'] is definedSeptember 27, 2010
Thanks a lot for the article, Bojhan. Fun to read and helpful to know how they're intended to be used. Will share it out!
And a quick question, of course. : P
I had an idea to use contextual links to allow fast editing of products referenced from nodes via a product reference field. Given the design constraints, it seems I should limit these "Edit product" links to the nodes that only reference a single product. Would you recommend any sort of "Edit products" link that would allow for editing multiple products at once? I'm not sure making it a faux-multistep form is really helpful, but I could feasibly alter the form if an "Edit products" link was used so that you step through editing every referenced product... but I'm not sure how helpful that would end up being. Seems more likely I'd want a page with edit elements for all the products at the same time, but I'm guessing that will cause plenty of problems with fields.
September 27, 2010
Nice post! The design was also inspired by Mark Boulton's work (he certainly used the cog icon) as well as Earl Miles' work on Panels and Views.
September 27, 2010
@seutje Thanks!
@Ryan Your problem is pretty complex since you are trying to provide an action for several items at once (referenced products). I suggest that you take a step in between, having a action like "List referenced products" (can probably be shorter) that goes to a page that lists all products related to that single product argument.
@Dries Yup it came forward from the "Edit everywhere" concept, which used a pen, example at http://www.flickr.com/photos/mboulton/3594826005/in/photostream/ - I think we will have enough opportunities in Drupal 8 to explore this more.
September 27, 2010
Post new comment