Drupal 7: Addressfield - Change the order of the inner fields

A request that often comes up is to change the order of the Addressfield fields.
In this example, we are creating a custom module in order to position the Country field at the bottom.
It is a very simple function, and the other elements can be positioned in a similar fashion.

<?php
/**
* Implements hook_field_widget_form_alter().
*/
function MYMODULENAME_field_widget_form_alter(&$element, $form_state, $context) { 
  if(!empty($element['#addressfield'])) {   
    $element['country']['#weight'] = 100;
  }
}

MYMODULENAME needs to be replaced with the real name of the custom module.

Tags: 
Drupal 7, Drupal Commerce, Drupal Quick Tips, Drupal theming

Recent Comments

Forward by Dries Buytaert, Founder and Project Lead, Drupal; CTO Acquia.

Order now from:

Managing Expectations Podcast with DrupalEasy

Author Interview http://tinyurl.com/8a8nxno

We provide the most Shiny Drupal Bits & Pixels

Since Drupal 4.x