You are here

function smart_ip_addressfield_default_values_alter in Smart IP 7.2

Implements hook_addressfield_default_values_alter(). Allows modules to alter the default values for an address field.

Parameters

$default_values: The array of default values. The country is populated from the 'default_country' widget setting.

$context: An array with the following keys:

  • field: The field array.
  • instance: The instance array.
  • address: The current address values. Allows for per-country defaults.

File

./smart_ip.module, line 278
Determines country, geo location (longitude/latitude), region, city and postal code of the user, based on IP address

Code

function smart_ip_addressfield_default_values_alter(&$default_values, $context) {

  // If no other default country was provided, set it to one retrieved from SmartIP.
  $smart_ip_session = smart_ip_session_get('smart_ip');
  if (empty($default_values['country']) && !empty($smart_ip_session['location']['country_code'])) {
    $default_values['country'] = $smart_ip_session['location']['country_code'];
  }
}