You are here

function _field_timer_text_formatter in Field Timer 7

Help function.

Build renderable array for Text formatter.

1 call to _field_timer_text_formatter()
field_timer_field_formatter_view in ./field_timer.module
Implements hook_field_formatter_view().

File

includes/field_timer.inc, line 13
Contains some help functions for formatters and settings forms.

Code

function _field_timer_text_formatter($items, $settings) {
  $elements = array();
  foreach ($items as $delta => $item) {
    $time = '';

    // Check what we should display - timer or countdown.
    switch ($settings['type']) {
      case 'auto':
        $interval = REQUEST_TIME - $item['timestamp'];
        $sign = '-';
        if ($interval > 0) {
          $sign = '+';
        }
        $time = $sign . format_interval(abs($interval), $settings['granularity']);
        break;
      case 'timer':
        $time = format_interval(REQUEST_TIME - $item['timestamp'], $settings['granularity']);
        break;
      case 'countdown':
        $time = format_interval($item['timestamp'] - REQUEST_TIME, $settings['granularity']);
        break;
    }
    $elements[$delta] = array(
      '#type' => 'markup',
      '#markup' => $time,
    );
  }
  return $elements;
}