LiTWol @ Oleg Terenchuk

  • Contact
  • About me

User login

What is OpenID?
To prevent automated spam submissions leave this field empty.
  • Log in using OpenID
  • Cancel OpenID login
  • Request new password

litwol's tweets

  • You just need to come to terms with yourself that no one is going to congratulate you for shit. — 1 year 4 weeks ago
  •  
  • 1 of 9
  • ››
more
Home

Creating custom fields using Drupal 7 field api

Submitted by litwol on Thu, 01/28/2010 - 06:03

** Work in progress **

This article describes which Drupal 7 field api hooks one must implement to create fully functional custom field. This field then may be usable on any fieldable object in Drupal 7.

// tells drupal which field(s) your module defines and implements
function hook_field_info() {}

// tells drupal which widgets your module defines and implements
// these widgets may be made available to other fields defined elsewhere (ex, core fields). but for our purpose i will describe how this hook interacts with hook_field_info()
function hook_field_widget_info() {}

// This hook defines the field schema. this is necessary because it tells drupal what columns to create in database where field's data will be stored. @todo: Find out whether custom table must be created or whether field_sql storage takes care of this completely.
function hook_field_schema($field) {}

// This tells drupal what formatters your module defines and implements as well as which fields this formatter is restricted to. this is only registry type hook, actual definition of formatters happens in hook_field_formatter_view.
function hook_field_formatter_info() {}

// This hook exposes settings that you users typically see on field edit page (ex: admin/structure/types/manage/%node_type/fields/%field_name
function hook_field_settings_form($field, $instance, $has_data) {}

// This hook defines field form. This is displayed on node form allowing users enter data.
function hook_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {}

// This seem to be mandatory. During form submit this function tells drupal whether the data submitted is considered empty or not. For example link field consist of link text and link URI. If text is entered without URI we should consider the field empty because text without link is useless.

function hook_field_is_empty($item, $field) {}
// This implements each formatter registered by this module inside hook_field_formatter_info(). this gets called during node view and this function is responsible returning renderable array that represents field's data.
function hook_field_formatter_view($obj_type, $object, $field, $instance, $langcode, $items, $display) {}

  • 2303 reads
Tags:
  • Drupal
  • Drupal 7
  • field api

3 reponses to "Creating custom fields using Drupal 7 field api"

1. I am so impressed! Thank you

Submitted by martin (not verified) on Mon, 05/17/2010 - 14:16.

I am so impressed! Thank you so much Dries for all you are doing for Drupal. Being part of Drupal is like being on a roller coaster. I know that I am part of something awesome. And I appreciate you as a leader, and so many contributors.

online casino

  • reply

2. Simply, in my opinion Drupal

Submitted by Ricky (not verified) on Sat, 05/15/2010 - 10:02.

Simply, in my opinion Drupal 7 API is harassing, not so useful, anyway thanks for sharing.


  • reply

3. Thanks for the post

Submitted by Richard McIntyre (not verified) on Fri, 03/26/2010 - 02:19.

Thanks for your post, I am extremely looking forward to Drupal 7 and am keen to see how much more streamlined the form api might get.

Form API is what I have wasted time on the most in Drupal. There are rumors that Drupal 7 also helps with keeping the $form_state variable in more shape. I was also loosing its post values when I used form_alter. Very frustrating!

Thanks again

Richard

  • reply

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.

More information about formatting options

To prevent automated spam submissions leave this field empty.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.

Recent posts

  • Developing PHP in VIM - VIM IDE for PHP
  • Creating custom fields using Drupal 7 field api
  • Creating 3d cube movieClip using Sprites and animating rotation through ActionsScript 3.0
  • Adding sprite from inside an external class onto stage and animating it using arrow key movement.
  • Playing with flash keyboard click events
  • Script to benchmark API execution time.
  • Very good dvcs guide
  • High throughput web architecture with drupal - *For authenticated users*
  • About me - Oleg Terenchuk
  • Note to self
  • Pre-generating drupal forms
  • Change memcached admin stats page
  • The cult of done

LiTWoL © Oleg Terenchuk - Hosted on Linode.com 360

I love Smashing Magazine!
Fervens Drupal theme by Leow Kah Thong. Designed by Design Disease and brought to you by Smashing Magazine.