You are here

function theme_addressfield_formatter__linear in Addressfield Tokens 7

Implements theme_field();

Themes an address field into "name, street1, street2, city state zip country"

2 theme calls to theme_addressfield_formatter__linear()
_webform_csv_data_addressfield in ./addressfield_tokens.components.inc
Format the submitted data of a component for CSV downloading.
_webform_display_addressfield in ./addressfield_tokens.components.inc
Display the result of a submission for a component.

File

./addressfield_tokens.theme.inc, line 62
Theme Controllers.

Code

function theme_addressfield_formatter__linear($vars) {
  $loc = $vars['address'];

  // If single line name is empty, construct it from first and last name.
  if (empty($loc['name_line'])) {
    $parts = array();
    if (!empty($loc['first_name'])) {
      $parts[] = $loc['first_name'];
    }
    if (!empty($loc['last_name'])) {
      $parts[] = $loc['last_name'];
    }
    $loc['name_line'] = join(' ', $parts);
  }

  // Determine which location components to render
  $out = array();
  if (!empty($loc['name_line']) && $vars['name_line']) {
    $out[] = $loc['name_line'];
  }
  if (!empty($loc['organisation_name']) && $vars['organisation_name']) {
    $out[] = $loc['organisation_name'];
  }
  if (!empty($loc['thoroughfare'])) {
    $out[] = $loc['thoroughfare'];
  }
  if (!empty($loc['premise']) && $vars['premise']) {
    $out[] = $loc['premise'];
  }
  if (!empty($loc['locality'])) {
    $out[] = $loc['locality'];
  }
  if (!empty($loc['administrative_area'])) {
    $out[] = $loc['administrative_area'];
  }
  if (!empty($loc['postal_code'])) {
    $out[] = $loc['postal_code'];
  }
  if ($loc['country'] != addressfield_tokens_default_country() && ($country_name = _addressfield_tokens_country($loc['country']))) {
    $out[] = $country_name;
  }

  // Render the location components
  $output = implode(', ', $out);
  return $output;
}