You are here

function countries_field_prepare_view in Countries 8

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

Implements hook_field_prepare_view().

File

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

Code

function countries_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) {
  global $language_content;
  foreach ($entities as $id => $entity) {
    if ($langcode == LANGUAGE_NONE) {
      $field_language = $entity ? $entity->language : $language_content->language;
    }
    else {
      $field_language = $langcode;
    }
    foreach ($items[$id] as $delta => $item) {
      if (!isset($item['country'])) {
        $items[$id][$delta]['value'] = $item['iso2'];
        if (!empty($item['iso2']) && ($country = country_load($item['iso2']))) {
          $items[$id][$delta]['country'] = $country;
          $items[$id][$delta]['safe_value'] = country_property($country, 'name', array(
            'langcode' => $field_language,
          ));
        }
        else {
          $items[$id][$delta]['country'] = FALSE;
          $items[$id][$delta]['safe_value'] = '';
        }

        // @todo: Remove post 7.x-2.x
        $items[$id][$delta]['safe'] = $items[$id][$delta]['safe_value'];
      }
    }
  }
}