Download & Extend

allow other modules to modify addressfield components

Project:Address Field
Version:7.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

Ireland (Republic) does not have a post code, but Northern Ireland does. The addressfield module includes the Northern Ireland counties in the drop-down when Ireland is selected - now technically it probably shouldn't, but the reality is this is what people expect, so I wouldn't go changing this. :)

However, Northern Ireland has a postcode and the postal code field does not appear when Ireland is selected, even though those counties appear in the drop-down. I tried modifying the form through a hook_form_alter() but as soon as I change the country to something else, and then back to Ireland, the post code field I added is lost as part of the AJAX changes.

I've patched addressfield to make the postcode field optional for Ireland, but I'd like to propose the provision of an alter hook so other modules have the ability to manipulate the form or data returned before it is rendered.

Comments

#1

#2

Status:active» needs review

Attached is a patch that adds an alter hook at the end of the addressfield_generate function allowing other modules to modify the generated format.

Example usage:

/**
* Implementation of hook_addressfield_generate_alter().
*/
function mymodule_addressfield_generate_alter(&$format, $address, $context = array()){
 
  if ($address['country'] == 'FR') {
    $format['locality_block']['administrative_area']['#title'] = t('Department');
    $format['locality_block']['administrative_area']['#required'] = TRUE;
    $format['locality_block']['administrative_area']['#options'] = array(
      "01 Ain" => t("01 Ain"),
      "02 Aisne" => t("02 Aisne"),
      ....
    );
  }

}
AttachmentSize
addressfield-hook_addressfield_generate_alter-1862100-2.patch 306 bytes
nobody click here