I would like to use the address field module in my module. How do I create an address field and an instance for that field. I haven't found any code in the module that defines what the array structure should look like.

I found this code in the commerce module (under modules/customer/commerce_customer.module):

if (empty($field)) {
  $field = array(
    'field_name' => $field_name,
    'type' => 'addressfield',
    'cardinality' => 1,
    'entity_types' => array('commerce_customer_profile'),
    'translatable' => FALSE,

  $field = field_create_field($field);

if (empty($instance)) {
  $instance = array(
    'field_name' => $field_name,
    'entity_type' => 'commerce_customer_profile',
    'bundle' => $profile_type['type'],
    'label' => t('Address'),
    'required' => TRUE,
    'widget' => array(
      'type' => 'addressfield_standard',
      'weight' => -10,
      'settings' => array(
        'format_handlers' => array('address', 'name-oneline'),
    'display' => array(),

I can modify that to meet my needs, if someone is familiar with this module and could point out some attributes that may be missing, I'll accept their response as an answer to this question.

Update The address that I'm importing may contain up to 6 lines for the street address (all for one location) as defined by RETS. Is it possible to store a street address this long in an address field? If not I can concatenate the extra addresses into the second address line.


2 Answers 2


I had a similar question these days, and I tried to see if the Features module could help. Features worked to me.

You can create the field by the UI and then export a feature with the address field already created.
After that you can move the inc files for your custom module and add an include on your .module file:


Then, you will need to add the some lines on your .info from the info file of the exported feature.

Your info file will need something like this:

dependencies[] = "features"    
dependencies[] = "text"

features[field][] = "node-article-field_address"

This question may help you too: Develop a module that adds a new content type with custom fields.

  • Don't have time to test atm but I'll accept your answer because it sounds legit
    – Arosboro
    Jan 24, 2012 at 3:46

This is also a useful link for creating just address field form values: http://drupal.org/node/970048

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.