O'Reilly logo

Drupal 7 Module Development by Ken Rickard, John Wilkins, Larry Garfield, Matt Butcher, Greg Dunlap, Matt Farina

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using formatters to display our field

Now that we've defined our field type, and we've created a widget to make it editable from a form, the only piece left is to decide how to display it in user output. (User output usually means the computer screen, but it could also mean an RSS feed, printed page, or various other types of output). Drupal lets us control that display using formatters.

Formatters follow a very similar pattern to field types and widgets. There is an info hook to define what formatters are available, and then there's a series of callbacks for all of the formatters our module defines. In most cases though, there's only one callback we need worry about.

Declaring a formatter

First, let's look at the info hook given here:

function ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required