You are here

function date_field_formatter in Date 5.2

Same name and namespace in other branches
  1. 5 date.module \date_field_formatter()

Implementation of hook_field_formatter().

File

date/date.module, line 151
Defines date/time field types for the Content Construction Kit (CCK).

Code

function date_field_formatter($field, $item, $formatter, $node) {

  // Prepare the node in case it is a view with multiple values
  // so it will display the right values.
  date_prepare_node($node);

  // There could be more than one date field in a view or on a node.
  // If date_id is set for this field and the delta doesn't match, don't display it.
  foreach ($node->date_id as $key => $id) {
    list($module, $nid, $field_name, $delta, $other) = explode(':', $id);
    if ($field_name != $field['field_name']) {
      return;
    }
    if (isset($item['#delta']) && $delta != $item['#delta']) {
      return;
    }
  }

  // Special test for repeating dates with no date id set.
  // Only display the start date unless we're showing all dates.
  if (empty($node->date_id) && empty($node->date_repeat_show) && !empty($field['repeat']) && isset($item['#delta']) && $item['#delta'] != 0) {
    return;
  }

  // Call the right theme for this formatter.
  $dates = date_formatter_process($field, $item, $node, $formatter);
  if ($formatter != 'format_interval') {
    $output = theme('date_display_combination', $field, $item, $dates, $node);
  }
  else {
    $output = theme('date_format_interval', $field, $item, $dates, $node);
  }
  return $output;
}