Show US State address as a full name instead of the 2 letter abbreviation in AddressField

Public

This will convert the Addressfield state (administrative_area) for US states from the abbreviation to the full name.

Get raw version
php
  1. <?php
  2. //in your module folder, in a folder called plugins/format/custom_addressfield_full_state.inc
  3. /**
  4.  * @file
  5.  * Display the full name of each state.
  6.  */
  7.  
  8. $plugin = array(
  9. 'title' => t('Display the full name of US states.'),
  10. 'format callback' => 'custom_addressfield_format_address_full_us_state',
  11. 'type' => 'address',
  12. 'weight' => -80,
  13. );
  14.  
  15. /**
  16.  * Format callback.
  17.  *
  18.  * @see CALLBACK_addressfield_format_callback()
  19.  */
  20. function custom_addressfield_format_address_full_us_state(&$format, $address, $context = array()) {
  21. if ($context['mode'] == 'render') {
  22. if (!empty($context['instance']['widget']['settings']['available_countries'])) {
  23. // If the country is the US we display the full state names
  24. if ($address['country'] == 'US') {
  25. $format['locality_block']['administrative_area']['#render_option_value'] = TRUE;
  26. }
  27. }
  28. }
  29. }
Get raw version
php
  1. <?php
  2. // in your custom.module file
  3. /**
  4.  * Implements hook_ctools_plugin_directory().
  5.  */
  6. function custom_addressfield_ctools_plugin_directory($module, $plugin) {
  7. if ($module == 'addressfield') {
  8. return 'plugins/' . $plugin;
  9. }
  10. }