You are here

function interval_field_formatter_view in Interval Field 7

Implements hook_field_formatter_view().

See also

interval_field_formatter_info()

File

./interval.module, line 128
Defines an interval field @copyright Copyright(c) 2011 Rowlands Group @license GPL v2+ http://www.fsf.org/licensing/licenses/gpl.html @author Lee Rowlands leerowlands at rowlandsgroup dot com

Code

function interval_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  switch ($display['type']) {

    // This formatter simply outputs the interval/period wrapped in a div.
    case 'interval_default':
      foreach ($items as $delta => $item) {
        $element[$delta] = array(
          '#type' => 'html_tag',
          '#attributes' => array(
            'class' => array(
              'interval-value',
            ),
          ),
          '#tag' => 'div',
          '#value' => interval_format_interval($item),
        );
      }
      break;

    // This formatter outputs the interval/period.
    case 'interval_raw':
      foreach ($items as $delta => $item) {
        $element[$delta] = array(
          '#markup' => check_plain(interval_format_interval($item)),
        );
      }
      break;

    // This formatter outputs the interval/period as a PHP date/time string.
    case 'interval_php':
      foreach ($items as $delta => $item) {
        $element[$delta] = array(
          '#markup' => check_plain(interval_php_interval($item)),
        );
      }
      break;
  }
  return $element;
}