You are here

public function UcAddressesUcCountryFieldHandler::outputValue in Ubercart Addresses 6.2

Same name and namespace in other branches
  1. 7 handlers/ubercart.handlers.inc \UcAddressesUcCountryFieldHandler::outputValue()

Overrides UcAddressesFieldHandler::outputValue().

The country field can be outputted in different formats.

Overrides UcAddressesFieldHandler::outputValue

File

handlers/ubercart.handlers.inc, line 276
Field handlers for Ubercart core address fields: first_name, last_name, company, etc.

Class

UcAddressesUcCountryFieldHandler
Class for the Ubercart country field.

Code

public function outputValue($value = '', $format = '') {
  if ($value === '') {
    $value = $this
      ->getAddress()
      ->getField($this
      ->getFieldName());
  }
  $country = $this
    ->getCountry($value);
  if (!$country) {
    return t('Unknown');
  }

  // Return country only if the country is not equal to the store's default country.
  if (preg_match('/\\_if$/', $format)) {
    if (uc_store_default_country() == $country->country_id) {
      return '';
    }
  }
  switch ($format) {
    case 'country_name':
    case 'country_name_if':
      return t($country->country_name);
    case 'country_code2':
    case 'country_code2_if':
      return $country->country_iso_code_2;
    case 'country_code3':
    case 'country_code3_if':
      return $country->country_iso_code_3;
  }

  // If no format is specified, return country name.
  return t($country->country_name);
}