You are here

function addtocal_field_formatter_view in Add to Cal 7

Implements hook_field_formatter_view().

File

./addtocal.module, line 133
addtocal.module General functions and hook implementations.

Code

function addtocal_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  switch ($display['type']) {
    case 'addtocal_view':
      $element = array();
      $date_element = date_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display);
      $view_mode = $display['settings']['view_mode'];
      if ($date_element) {
        $element[0]['date'] = $date_element[0];
        list($entity_id) = entity_extract_ids($entity_type, $entity);
        $info = addtocal_extract_event_info($entity_type, $entity, $entity_id, $field['field_name'], $display);
        $dates = field_get_items($entity_type, $entity, $field['field_name']);
        $start_date = $dates[count($dates) - 1]['value'];

        // Build URLs
        $base_url = $entity_type . '/' . $entity_id . '/' . $field['field_name'] . '/' . $view_mode;
        $ics_url = $base_url . '/addtocal.ics';
        $google_url = $base_url . '/addtocal-google';
        $yahoo_url = $base_url . '/addtocal-yahoo';

        // Check setting for past events and show widget accordingly
        if (strtotime($start_date) >= time() || $display['settings']['past_events'] == TRUE && strtotime($start_date) < time()) {
          $element[0] += addtocal_render($entity_type, $entity_id, $info['start'], $info['end'], $info['timezone'], $info['url'], $ics_url, $google_url, $yahoo_url);
        }
        return $element;
      }
      break;
  }
}