Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Custom Contextual Links Module

Parent Feed: 

January 9th, 2012

In the Drupal community the phrase “There’s a module for that” is pretty much synonymous with Apple’s “There’s an app for that”. So it was a bit surprising when Trent, ImageX’s ‘walking module encyclopedia’, mentioned the lack of an existing module allowing developers to add links to the contextual links widgets in Drupal 7.

There are a number of Drupal 6 modules that create a nice shortcut to edit/delete a node or to configure a block without actually clicking through the entire menu structure. Developers that used any of these modules immediately added them to their own personal ‘must install’ module lists and as a result, and much to the delight of the community, this became a core feature in Drupal 7.

On it’s own the core module adds contextual link widgets to nodes and blocks and there are a number of modules that add their own links as well. Previously, the only way to add custom links was to create another smaller module (a step that a large part of the community wanted to be able to skip). So this is where the idea for a Custom Contextual Links (CCL) module came in… to give administrators an interface to add custom links that can be attached to nodes and blocks.

Version 1.0

The first version of the module had a relatively limited set of features. With it developers were able to create links that attached to either:

  • All nodes
  • All nodes of a specific content type
  • One specific node
  • All blocks
  • A specific block

The ability to use a node id token in link path was also added as a bonus. This works in connection with links attached to nodes and allows one to create dynamic links in connection with node objects.

Version 1.1

One of the first responses after the release of the stable version was in regards to the custom token. Lullabot’s Jeff Eaton who had previously written an article in Module Mondays pointed out that it would make more sense to use core tokens. So this was first in a list of changes to implement to help improve the module.

Custom Contextual Links Step 1. Use tokens in the URL and title.

Scott Jordison then recommended attaching links to views (This, by the way, is a shining example of why the Drupal community is so awesome. Instead of just requesting this feature Scott supplied a constant stream of patches that added this feature to CCL.) Now you can attach your custom link to:

  • All views
  • All displays of a specific view
  • A specific display of a view

These suggestions prompted a rewrite of the core of CCL to make it more modular. This involved removing the ability to add links to blocks and putting them into their own sub-module. The same applied to the views option.

The last thing to add was the ability to quickly publish/promote/sticky a node through the contextual widget. This feature might need extra attention in the future but for now you can attach a link to:

  • Publish/Unpublish
  • Promote/remove to/from front page
  • Make sticky/unsitcky
  • To nodes (all, by content type or specific). Users will only be able to see these links on nodes where they have the ‘update’ permission.

Custom Contextual Links Step 3. Attach custom links to all orspecific nodes/bloc

The final result looks like this:

Custom Contextual Links Module Final Result

Version 1.?

So what else is there to add? One thing on the agenda is to make all the settings exportable through features (time didn’t allow for this in Version 1.1). Revisiting access settings and looking into integration with rules is also an option to explore.

Have suggestions of your own? Try out the latest version of CCL and give your feedback.

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web