You are here

function jstimer_field_formatter_view in Javascript Timer 7

Implements hook_field_formatter_view(). Normal behavior for two date fields is to use value1 where it is available. Use value2 only if value1 is empty.

File

./jstimer.field.inc, line 74
Field hooks to implement a jstimer field.

Code

function jstimer_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $settings = $display['settings'];
  $widgets = jstimer_get_widgets();
  $widget_names = array();
  foreach ($widgets as $widget) {
    $widget_names[] = $widget->name;
  }
  if (in_array($display['type'], $widget_names)) {
    foreach ($items as $delta => $item) {
      if (!empty($entity->date_id) && !in_array($delta, $selected_deltas)) {
        continue;
      }
      else {
        $dates = date_formatter_process('date_default', $entity_type, $entity, $field, $instance, $langcode, $item, $display);
        if (empty($item['value'])) {
          $widget_args = _jstimer_date_to_widget($dates['value2']['formatted_iso'], $display['type'], $settings);
        }
        else {
          $widget_args = _jstimer_date_to_widget($dates['value']['formatted_iso'], $display['type'], $settings);
        }
        $element[$delta] = array(
          '#markup' => theme('jstimer', $widget_args),
        );
      }
    }
  }
  return $element;
}