You are here

function countries_i18n_field_formatter_view in Countries 8

Same name and namespace in other branches
  1. 7.2 modules/countries_i18n/countries_i18n.module \countries_i18n_field_formatter_view()

Implements hook_field_formatter_view().

File

modules/countries_i18n/countries_i18n.module, line 143
Provides translation for countries module.

Code

function countries_i18n_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $settings = $display['settings'];
  switch ($display['type']) {
    case 'country_default_i18n':
      foreach ($items as $delta => $item) {
        $element[$delta] = array(
          '#markup' => check_plain(countries_i18n_translate($item['iso2'], 'name', $item['country']->name)),
        );
      }
      break;
    case 'country_official_i18n':
      foreach ($items as $delta => $item) {
        $official_name = isset($item['country']->official_name) ? $item['country']->official_name : $item['country']->name;
        $element[$delta] = array(
          '#markup' => check_plain(countries_i18n_translate($item['iso2'], 'official_name', $official_name)),
        );
      }
      break;
  }
  return $element;
}