06 Nov 2009

Better Know a Module: Suggested Terms

garfield's picture
Senior Architect and Consultant
3

Everyone knows the top-tier Drupal modules, but with over 4,000 5,000 modules available for Drupal it's no surprise that many useful ones go unnoticed. As part of its mission to raise awareness of these unsung heroes, Palantir is presenting this series of articles on modules that carry more than their weight in code.

In part 2 of our 5,046 part series, we present: Suggested Terms

Once upon a time...

Suggested terms has probably the most interesting back story of any of Palantir's modules. Back in the summer of 2007, Palantir was looking to hire new programming talent. Naturally we wanted someone who either already had strong Drupal-fu or would be able to develop it quickly. We found a promising prospect, but he didn't know Drupal yet so we decided to hire him to write a module to see how he'd do.

Meanwhile, elsewhere in the forest

This was still early in Palantir's Drupal lifetime, so we were still struggling with some features or lack thereof. One in particular that we found annoying was taxonomy forms, specifically free tagging. With normal taxonomy, you get a select list of available terms so you know what is available but no way to add terms on the fly. With a free-tagging vocabulary, you get a textfield with autocomplete but no way to see what tags are already available unless you happen to start typing a term that already exists. We wanted to have our cake and eat it too, the way a number of other systems do with clickable links on each vocabulary on the node edit page in addition to the free-form.

We had an idea for a module we needed written, and we had someone who we wanted to have try and write a module. Hey, look, synergy! It was a good test case for him, too. We spec'ed out what was needed, and the resulting module would need to use FAPI and form_alter, the theme system, nodes, taxonomy, Javascript/jQuery... all of the fun stuff.

So with a proper spec prepared we sent it off to our would-be employee to see what he'd come up with.

And they married...

The resulting module was actually pretty darned good. We had some feedback on it, and some coding style improvements needed, but for a first module it was very high quality. It also did exactly what we needed. Once enabled, the module can be configured to show the most recently used terms, most frequently used terms, or simply terms alphabetically, and can be limited to any number of possible terms. Those terms show up below each vocabulary that is defined as allowing free-tagging, so that the do not interfere with the existing auto-complete functionality. That still works fine. However, clicking on any of the listed terms magically adds that term to the textfield without duplicates.

Have a look at the screen shot below to see it in action:

And they branched happily ever after

With that much success, there was only one thing to do: We offered our prospective developer a position. And while he didn't end up joining the team, we did end up with the module, so like good open source citizens we released it on Drupal.org as Suggested Terms. I've been maintaining it for Palantir ever since.

It's decently popular, too, with several hundred recorded users according to Drupal.org. At this point I almost never build a blog without it, and it's running now on this very Web site. It's a simple little module that really makes free tagging shine.

There's always a sequel

Naturally, Suggested Terms has attracted its share of issue submissions. That includes a number of feature additions and bug fixes, and even one security release. (Sorry.) So far we've kept on top of them, but one common feature request that comes up (often mis-filed as a bug) is support for other modules that use taxonomy in some way that are not the normal taxonomy form. Due to the way form_alter works, that's not something we can do. Each form that needs to be altered would need its own specific integration, and possibly configuration. Right now it's not really set up to do that, and it would be too much work to individually support every other module.

That said, I'm very open to expanding Suggested Terms into an API. Perhaps in Drupal 7 the improvements to FAPI will make it easier to do. I'm not really sure. While we're not looking for individual support for every other module, patches to generalize the Suggested Terms approach so that it can be used in more places are certainly welcome.

What about getting it in core? Well, at one point I thought it should be a base feature of the taxonomy module. However, as with most other parts of core functionality one man's feature is another man's design flaw. If it's not configurable and removable, it's not a good idea. Otherwise we end up with hard-coded teddy bears.

However, Taxonomy terms in Drupal 7 are now Fields, aren't they? Fields take widgets, don't they? Widgets can be configured and swapped in and out, can't they?

Hmmm... Volunteers?

Comments

Similar module

I didn't know about this one, which seems like a nice simple and clean solution, but there is a quite similar module called active_tags which seems to be a little bit more used according to usage stats, but also a little bit heavier.

Nice module Albert, Active

Nice module Albert, Active Tags rocks! Can't wait to use it.

- Sean Bannister

just what I needed

In a little site I use to organize movies with friends, one ask me exactly this module functionality, and some days after I read you :-)

so, thanks !