Check your version

This video covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.

Alternate resources: 

Providing Drupal With Meta-Data About A Custom Field

Video loading...

Transcripts: 
Transcript language code: 
eng

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:08
    The first step to defining acustom field type is
  • 0:10
    implementing hook_field_info and providing Drupal
  • 0:13
    with some basic metadata about our field,
  • 0:16
    things like the human readable label for our field type
  • 0:18
    and the default widget and formatter to use for the field.
  • 0:22
    In this lesson, we'll start by implementing hook_field_info.
  • 0:27
    Then in order to get our field to show up in the admin UI,
  • 0:30
    we'll need to define a default widget and formatter.
  • 0:33
    Since those don't exist yet for our field
  • 0:36
    we'll implement hook_field_widget_info

Providing Drupal with Meta-Data About a Custom Field

Loading...

The first step to defining a custom field is telling Drupal that our module provides a field. This is done by implementing hook_field_info(), hook_field_formatter_info(), and hook_field_widget_info(). The combination of which provides some basic information about our field including a label, description, default settings, and basic information about how the field will be formatted and what widgets can be used for data collection.

In this lesson we'll implement the basics for the following hooks:

Doing so will allow us to enable our module and see our new field type appear in the list of available fields to add to a content type. The field won't do much beyond that yet, but it's a good start towards telling Drupal about our custom RGB field type.

If you want to just follow along and look at the already written code you can grab a copy in the companion files section of this page and use that to follow along.

Downloads: 
Log in or sign up to download companion files.

Additional resources:
There are no resources for this video. If you believe there should be, please contact us.