18.10.2016 Views

Drupal 7 Module Development

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 7<br />

Although an advanced topic, pluggable field storage is one of<br />

the major new features of the Field API and is another option for<br />

handling remote data sources in <strong>Drupal</strong>.<br />

Creating our new field type<br />

Field types are defined by modules, so let's start by creating a new module called<br />

dimfield.module. Its info file is as follows:<br />

name = Dimensions field<br />

description = A Field offering height, width, and depth<br />

package = <strong>Drupal</strong> 7 <strong>Development</strong><br />

core = 7.x<br />

files[] = dimfield.module<br />

Declaring the field<br />

Now in dimfield.module, we need to implement hook_field_info(), which is<br />

how we tell <strong>Drupal</strong> about our new field type.<br />

function dimfield_field_info() {<br />

return array(<br />

'dimensions' => array(<br />

'label' => t('Dimensions'),<br />

'description' => t(<br />

'This field stores a height and width, and depth.'),<br />

'settings' => array('num_dimensions' => 2),<br />

'instance_settings' => array(<br />

'max_height' => 0,<br />

'max_width' => 0,<br />

'max_depth' => 0,<br />

),<br />

'default_widget' => 'dimfield_combined',<br />

'default_formatter' => 'dimfield_default',<br />

),<br />

);<br />

}<br />

[ 185 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!