You are here

function countries_field_diff_view in Countries 8

Same name and namespace in other branches
  1. 7.2 countries.diff.inc \countries_field_diff_view()

Diff field callback for parsing country field comparative values.

File

./countries.diff.inc, line 11
Provide diff field functions for the Countries module.

Code

function countries_field_diff_view($items, $context) {
  $field = $context['field'];
  $instance = $context['instance'];
  $settings = $context['settings'];
  $langcode = $context['language'];
  $diff_items = array();
  foreach ($items as $delta => $item) {
    if (empty($item['country']) && !empty($item['iso2'])) {
      $item['country'] = country_load($item['iso2']);
    }
    $country = $item['country'];
    switch ($settings['format']) {
      case 'country_official':
        if (!empty($country->official_name)) {
          $diff_items[$delta] = country_property($country, 'official_name', array(
            'langcode' => $langcode,
            'sanitize' => FALSE,
          ));
        }
        else {
          $diff_items[$delta] = country_property($country, 'name', array(
            'langcode' => $langcode,
            'sanitize' => FALSE,
          ));
        }
        break;
      case 'country_alpha_2':
        $diff_items[$delta] = $country->iso2;
        break;
      case 'country_alpha_3':
        $diff_items[$delta] = empty($country->iso3) ? '---' : $country->iso3;
        break;
      case 'country_number':
        $diff_items[$delta] = theme('countries_number', array(
          'country' => $country,
        ));
        break;
      case 'country_default':
      default:
        $diff_items[$delta] = country_property($country, 'name', array(
          'langcode' => $langcode,
          'sanitize' => FALSE,
        ));
        break;
    }
    if (!empty($settings['append_iso'])) {
      $diff_items[$delta] .= ' (' . $country->iso2 . ')';
    }
  }
  return $diff_items;
}