You are here

function addressfield_default_values in Address Field 7

Returns an array of default values for the addressfield form elements.

Parameters

$field: The field array.

$instance: The instance array.

$address: The current address values, if known. Allows for per-country defaults.

Return value

An array of default values.

4 calls to addressfield_default_values()
addressfield_auto_creation in ./addressfield.module
Auto creation callback for an addressfield value array.
addressfield_field_widget_form in ./addressfield.module
Implements hook_field_widget_form()
addressfield_set_target in ./addressfield.feeds.inc
Callback for hook_feeds_processor_targets_alter().
_addressfield_devel_generate in ./addressfield.devel_generate.inc

File

./addressfield.module, line 412
Defines a field for attaching country-specific addresses to entities.

Code

function addressfield_default_values($field, $instance, array $address = array()) {
  $available_countries = _addressfield_country_options_list($field, $instance);
  $default_country = $instance['widget']['settings']['default_country'];

  // Resolve the special site_default option.
  if ($default_country == 'site_default') {
    $default_country = variable_get('site_default_country', '');
  }

  // Fallback to the first country in the list if the default country is not
  // available, or is empty even though the field is required.
  $not_available = $default_country && !isset($available_countries[$default_country]);
  $empty_but_required = empty($default_country) && !empty($instance['required']);
  if ($not_available || $empty_but_required) {
    $default_country = key($available_countries);
  }
  $default_values = array(
    'country' => $default_country,
    'name_line' => '',
    'first_name' => '',
    'last_name' => '',
    'organisation_name' => '',
    'administrative_area' => '',
    'sub_administrative_area' => '',
    'locality' => '',
    'dependent_locality' => '',
    'postal_code' => '',
    'thoroughfare' => '',
    'premise' => '',
    'sub_premise' => '',
    'data' => '',
  );

  // Allow other modules to alter the default values.
  $context = array(
    'field' => $field,
    'instance' => $instance,
    'address' => $address,
  );
  drupal_alter('addressfield_default_values', $default_values, $context);
  return $default_values;
}