You are here

function sheetnode_field_formatter_view in Sheetnode 7.2

Same name and namespace in other branches
  1. 7 sheetnode.module \sheetnode_field_formatter_view()

Implements hook_field_formatter_view().

File

./sheetnode.module, line 794
Module file for the sheetnode module.

Code

function sheetnode_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  switch ($display['type']) {
    case 'sheetfield_default':
      foreach ($items as $delta => $item) {
        $output = '';
        if (!empty($item['name'])) {
          $output .= '<div class="sheetfield-title">' . $item['name'] . '</div>';
        }
        $output .= _sheetnode_inject(drupal_clean_css_identifier('sheetfield-' . $field['field_name'] . '-' . $langcode . '-' . $delta), _sheetnode_sheetfield_aliases($field['field_name'], $instance['label'], $item, $delta), $item['value'], FALSE, isset($entity) && $entity == 'node' ? array(
          'entity-type' => $entity_type,
          'oid' => @$entity->nid,
        ) : NULL);
        $element[$delta] = array(
          '#markup' => $output,
        );
      }
      break;
    case 'socialcalc_date':
      module_load_include('inc', 'sheetnode', 'socialcalc');
      foreach ($items as $delta => $item) {
        $value = $item['value'];
        $timezone = isset($item['timezone']) ? $item['timezone'] : '';
        $timezone = date_get_timezone($field['settings']['tz_handling'], $timezone);
        $timezone_db = date_get_timezone_db($field['settings']['tz_handling']);
        $db_format = date_type_format($field['type']);
        $date = new DateObject($value, $timezone_db, $db_format);
        $date
          ->limitGranularity($field['settings']['granularity']);
        date_timezone_set($date, timezone_open($timezone));
        $element[$delta] = array(
          '#markup' => socialcalc_import_date($date),
        );
      }
      break;
  }
  return $element;
}