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

Creating our new field type

Field types are defined by modules, so let's start by creating a new module called dimfield.module. Its info file is as follows:

name = Dimensions field
description = A Field offering height, width, and depth
package = Drupal 7 Development
core = 7.x
files[] = dimfield.module

Declaring the field

Now in dimfield.module, we need to implement hook_field_info(), which is how we tell Drupal about our new field type.

function dimfield_field_info() { return array( 'dimensions' => array( 'label' => t('Dimensions'), 'description' => t( 'This field stores a height and width, and depth.'), 'settings' => array('num_dimensions' => 2), 'instance_settings' => array( 'max_height' => 0, 'max_width' => 0, 'max_depth' => 0, ), 'default_widget' ...

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