You are here

function theme_addressfield_formatter__citystate in Addressfield Tokens 7

Implements theme_field();

Themes an address field into "city state, country"

File

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

Code

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

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

  // If there's no location, render an alternate
  if (empty($out)) {
    return '';
  }

  // Render the location components
  $output = '<span class="addressfield-citystate">' . implode(', ', $out) . '</span>';
  return $output;
}