You are here

function countries_field_formatter_view in Countries 7

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

Implements hook_field_formatter_view().

File

./countries.module, line 431

Code

function countries_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  foreach ($items as $delta => $item) {
    $country = $item['country'];
    switch ($display['type']) {
      case 'country_default':
        $element[$delta]['#markup'] = $item['safe'];
        break;
      case 'country_official':
        if (!empty($country->official_name)) {
          $element[$delta]['#markup'] = check_plain($country->official_name);
        }
        else {
          $element[$delta]['#markup'] = $item['safe'];
        }
        break;
      case 'country_alpha_2':
        $element[$delta]['#markup'] = check_plain($country->iso2);
        break;
      case 'country_alpha_3':
        $element[$delta]['#markup'] = empty($country->iso3) ? '---' : check_plain($country->iso3);
        break;
      case 'country_number':
        $element[$delta]['#markup'] = theme('countries_number', array(
          'country' => $country,
        ));
        break;
      default:
        list(, $icon_module, $icon_type, $icon_set_name) = explode('_', $display['type'], 4);
        if (module_exists($icon_module)) {

          // countryicons formatters
          switch ($icon_module) {
            case 'countryicons':
              $variables = array(
                'code' => $country->iso2,
                'iconset' => $icon_set_name,
                'alt' => $country->iso2,
                'title' => $country->name,
              );
              if ($icon_type == 'sprite') {
                $element[$delta]['#markup'] = theme('countryicons_icon_sprite', $variables);
              }
              else {

                // Type 'image' is the default.
                $element[$delta]['#markup'] = theme('countryicons_icon', $variables);
              }
              break;
          }
        }
        break;
    }
  }
  return $element;
}