You are here

function hms_field_field_formatter_view in HMS Field 7

Implements hook_field_formatter_view().

File

./hms_field.module, line 240
Provides an hms_field functionality.

Code

function hms_field_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  if ($display['type'] === 'hms_default_formatter') {
    foreach ($items as $delta => $item) {
      $element[$delta]['#theme'] = 'hms';
      $element[$delta]['#value'] = $item['value'];
      $element[$delta]['#format'] = $display['settings']['format'];
      $element[$delta]['#leading_zero'] = $display['settings']['leading_zero'];
    }
  }
  else {
    if ($display['type'] === 'hms_natural_language_formatter') {
      foreach ($items as $delta => $item) {
        $element[$delta]['#theme'] = 'hms_natural_language';
        $element[$delta]['#value'] = $item['value'];
        $element[$delta]['#format'] = '';
        foreach ($display['settings']['display_formats'] as $fragment) {
          if ($fragment) {
            $element[$delta]['#format'] .= ':' . $fragment;
          }
        }
        if (!strlen($element[$delta]['#format'])) {
          $element[$delta]['#format'] = implode(':', array_keys($display['settings']['display_formats']));
        }
        else {
          $element[$delta]['#format'] = substr($element[$delta]['#format'], 1);
        }
        $element[$delta]['#separator'] = $display['settings']['separator'];
        $element[$delta]['#last_separator'] = $display['settings']['last_separator'];
      }
    }
  }
  return $element;
}