You are here

function countries_field_formatter_view in Countries 8

Same name and namespace in other branches
  1. 7.2 countries.fields.inc \countries_field_formatter_view()
  2. 7 countries.module \countries_field_formatter_view()

Implements hook_field_formatter_view().

File

./countries.fields.inc, line 222
All field related code.

Code

function countries_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  global $language_content;
  $element = array();
  $map = array(
    'country_default' => 'name',
    'country_official' => 'official_name',
    'country_alpha_2' => 'iso2',
    'country_alpha_3' => 'iso3',
    'country_number' => 'numcode',
    'country_continent' => 'continent',
    'country_continent_code' => 'continent_code',
  );
  if ($langcode == LANGUAGE_NONE) {
    $field_language = $entity ? $entity->language : $language_content->language;
  }
  else {
    $field_language = $langcode;
  }
  foreach ($items as $delta => $item) {
    $country = $item['country'];
    if (empty($country)) {
      continue;
    }
    elseif (isset($map[$display['type']])) {
      $element[$delta]['#markup'] = country_property($country, $map[$display['type']], array(
        'langcode' => $field_language,
      ));
    }
    elseif ($display['type'] == 'country_icon') {
      $variables = array(
        'country' => $country,
        'settings' => $display['settings'],
        'langcode' => $field_language,
      );
      $element[$delta]['#markup'] = theme('country_icon_adapter', $variables);
    }
    else {
      $element[$delta]['#markup'] = $item['safe_value'];
    }
  }
  return $element;
}