You are here

function theme_getlocations_addressfield_convert in Get Locations 7

Same name and namespace in other branches
  1. 7.2 getlocations.module \theme_getlocations_addressfield_convert()

Returns an array of an address from the addressfield module converted for use in getlocations.

from location module

Parameters

array $variables: An associative array containing:

  • address: an array of address components.
1 theme call to theme_getlocations_addressfield_convert()
getlocations_addressfield_convert in ./getlocations.module
Function

File

./getlocations.module, line 7782
getlocations.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function theme_getlocations_addressfield_convert($variables) {
  $address = $variables['address'];
  $location = array();
  if (is_array($address) && !empty($address)) {
    $name = array();
    if (isset($address['name_line']) && $address['name_line']) {
      $name[] = $address['name_line'];
    }
    if (isset($address['first_name']) && $address['first_name']) {
      if (isset($address['last_name']) && $address['last_name']) {
        $name[] = $address['first_name'] . ' ' . $address['last_name'];
      }
      else {
        $name[] = $address['first_name'];
      }
    }
    elseif (isset($address['last_name']) && $address['last_name']) {
      $name[] = $address['last_name'];
    }
    if (isset($address['organisation_name']) && $address['organisation_name']) {
      $name[] = $address['organisation_name'];
    }
    $location['name'] = count($name) ? implode(", ", $name) : '';
    $location['street'] = isset($address['thoroughfare']) ? $address['thoroughfare'] : '';
    $additional = array();
    if (isset($address['premise']) && $address['premise']) {
      $additional[] = $address['premise'];
    }
    if (isset($address['sub_premise']) && $address['sub_premise']) {
      $additional[] = $address['sub_premise'];
    }
    $location['additional'] = count($additional) ? implode(", ", $additional) : '';
    $city = array();
    if (isset($address['dependent_locality']) && $address['dependent_locality']) {
      $city[] = $address['dependent_locality'];
    }
    if (isset($address['locality']) && $address['locality']) {
      $city[] = $address['locality'];
    }
    $location['city'] = count($city) ? implode(", ", $city) : '';
    $admin_area = array();
    if (isset($address['sub_administrative_area']) && $address['sub_administrative_area']) {
      $admin_area[] = $address['sub_administrative_area'];
    }
    if (isset($address['administrative_area']) && $address['administrative_area']) {
      $admin_area[] = $address['administrative_area'];
    }
    $location['province_name'] = count($admin_area) ? implode(", ", $admin_area) : '';
    $location['postal_code'] = isset($address['postal_code']) ? drupal_strtoupper($address['postal_code']) : '';
    $location['country_name'] = isset($address['country_name']) ? $address['country_name'] : $address['country'];
    $location['country'] = $address['country'];
  }
  return $location;
}