Skip to main content

Certified to Rock field

An article from ComputerMinds - Building with Drupal in the UK since 2005.
19th Jan 2011

Steven Jones

Senior Developer

Certified to Rock is a site that allows you to look-up user names, and see their 'certified to rock' score. is a way that community members and employers can get a sense of someone's involvement with the Drupal project. The site uses a custom algorithm that gathers publicly available information which is then distilled down into a score on a scale from one to eleven.

I've been wanting to build an easy way to bring this rating into a Drupal site to add an additional metric to user profiles. Until recently this wouldn't have been a simple undertaking, but a few days ago, Certified to Rock added a JSON web service, making it really easy to get Certified to Rock ratings. I took the opportunity to learn the Drupal 7 field API and decided to take the plunge and build a module that adds a new field that gets the Certified to Rock score of the user ID that you put into the field.

Thus, Certified to Rock field was born! You can add it to any entity and enter the user ID, and get the Certified to Rock score back!

Field Info API

This was my first real venture into any of the Field API of Drupal 7, and I came out relatively happy. Total coding took under four hours, so it was pretty quick, and the amazing examples module was incredibly handy for making a fast start.

There are three major APIs that you can implement to add something to the fields info system:

  1. Field types - This is how you tell Drupal about your field, and the database columns that it needs. You can additionally implement validation and other hooks, to ensure validity of your data and more. The important distinction from CCK in Drupal 6 is that this can all happen without a form, and in fact you must code like this. Forms become just another user of Drupal's APIs, not an integral part of them. Yey!
  2. Field Widgets - So this is the formy bit, widgets are essentially the editing side of your field. My field was a simple(-ish) text box, but you can put whatever you like here. Widgets are really easy to build, but if you're adding a new field, you might find that there is already a widget out there that will do what you want, and you can just tell Drupal that people can use that widget instead of re-inventing the wheel.
  3. Field Formatters - The output, turning the field's data into something presentable. These were always easy to create, but were a bit of a black art of knowing exactly what to name things for it all to work, now in Drupal 7 the hooks are much more descriptive, making it even simpler than ever to build a new formatter. If your formatter supports options it's now painfully straightforward to add an options form. Drupal takes care of storing the data for you, allowing you to focus on what matters: your functionality.

That's my brief first impressions of the Field Info API in Drupal 7. I'm sure we'll be writing about it again soon.

Certified to Rock field

The field works, and I've released a stable version to play with, but there are a number of outstanding issues I'd like to get resolved:

  1. Updating scores on cron. Currently when re-saving the entity the Certified to Rock score will get updated, but it won't if you're not saving the entity. I'd like to process all entities on cron, and update the scores.
  2. Allow entering of Usernames. I'd really like to allow people to just enter their user name, and then look-up their user ID, but I don't know of an easy way to do this at the moment. Suggestions welcome!

I also need to make sure that the field works with Views, because we're all going to want to sort by Certified to Rock rating, aren't we?

[EDIT] Computerminds are not affiliated with Growing venture solutions, the crazy cats behind Certified to Rock

Hi, thanks for reading

ComputerMinds are the UK’s Drupal specialists with offices in Bristol and Coventry. We offer a range of Drupal services including Consultancy, Development, Training and Support. Whatever your Drupal problem, we can help.