You are here

function date_field_formatter_view in Date 7

Same name and namespace in other branches
  1. 7.3 date.field.inc \date_field_formatter_view()
  2. 7.2 date.field.inc \date_field_formatter_view()

Implements hook_field_formatter_view().

Useful values:

$entity->date_id If set, this will show only an individual date on a field with multiple dates. The value should be a string that contains the following values, separated with colons:

  • module name of the module adding the item
  • node nid
  • field name
  • delta value of the field to be displayed
  • other information the module's custom theme might need

Used by the calendar module and available for other uses. example: 'date:217:field_date:3:test'

$entity->date_repeat_show If true, tells the theme to show all the computed values of a repeating date. If not true or not set, only the start date and the repeat rule will be displayed.

File

./date.field.inc, line 95
Field hooks to implement a date field.

Code

function date_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $settings = $display['settings'];
  $formatter = $display['type'];
  $vars = array(
    'entity' => $entity,
    'entity_type' => $entity_type,
    'field' => $field,
    'instance' => $instance,
    'langcode' => $langcode,
    'items' => $items,
    'display' => $display,
    'dates' => array(),
  );

  // See if we are only supposed to display a selected
  // item from multiple value date fields.
  $selected_deltas = array();
  if (!empty($entity->date_id)) {
    foreach ((array) $entity->date_id as $key => $id) {
      list($module, $nid, $field_name, $selected_delta, $other) = explode(':', $id);
      if ($field_name == $field['field_name']) {
        $selected_deltas[] = $selected_delta;
      }
    }
  }
  switch ($display['type']) {
    case 'format_interval':
      foreach ($items as $delta => $item) {
        if (!empty($entity->date_id) && !in_array($delta, $selected_deltas)) {
          continue;
        }
        else {
          $vars['delta'] = $delta;
          $vars['item'] = $item;
          $vars['dates'] = date_formatter_process($formatter, $entity_type, $entity, $field, $instance, $langcode, $item, $display);
          $element[$delta] = array(
            '#markup' => theme('date_display_interval', $vars),
          );
        }
      }
      break;
    default:
      foreach ($items as $delta => $item) {
        if (!empty($entity->date_id) && !in_array($delta, $selected_deltas)) {
          continue;
        }
        else {
          $vars['delta'] = $delta;
          $vars['item'] = $item;
          $vars['dates'] = date_formatter_process($formatter, $entity_type, $entity, $field, $instance, $langcode, $item, $display);
          $element[$delta] = array(
            '#markup' => theme('date_display_combination', $vars),
          );
        }
      }
      break;
  }
  return $element;
}