You are here

function flickrfield_field_formatter_view in Flickr 7

Implements hook_field_formatter_view(). @todo: the theme definitions for our field-formatters should be removed from flickrfield_theme() and implemented here @ see https://drupal.org/node/728792 (section "Changed! Hook Formatter")

File

field/flickrfield.module, line 220
Defines a Flickr field type.

Code

function flickrfield_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $sizes = array_keys(flickr_photo_sizes());
  foreach ($items as $delta => $item) {

    // Use the first element (set or photo ID) of each item as a cache key.
    if ($cache = cache_get('flickrfield_' . key($item) . '_' . reset($item), 'cache')) {
      $element[$delta]['#markup'] = $cache->data;
    }
    else {
      $variables = array(
        '#node' => $entity,
        '#item' => $item,
        '#formatter' => $display['type'],
        '#field_name' => $field['field_name'],
      );
      $element[$delta]['#markup'] = theme('flickrfield_formatter_' . $display['type'], $variables);
      cache_set('flickrfield_' . key($item) . '_' . reset($item), $element[$delta]['#markup'], 'cache', time() + variable_get('flickrfield_refresh', 24) * 60 * 60);
    }
  }
  return $element;
}