You are here

function template_preprocess_timefield in Timefield 7

Same name and namespace in other branches
  1. 1.0.x timefield.module \template_preprocess_timefield()

Preprocess function for the timefield.

File

./timefield.module, line 894
Defines a Field API field for time

Code

function template_preprocess_timefield(&$variables) {
  if ($variables['format'] == 'default') {

    // Encode the time elements.
    $variables['time']['value'] = check_plain($variables['time']['value']);
    $variables['time']['formatted_value'] = trim(timefield_integer_to_time($variables['settings']['display_format'], $variables['time']['value']));
    $variables['time']['time'] = $variables['time']['formatted_value'];
    if (isset($variables['time']['value2'])) {
      $variables['time']['value2'] = check_plain($variables['time']['value2']);
      $variables['time']['formatted_value2'] = trim(timefield_integer_to_time($variables['settings']['display_format'], $variables['time']['value2']));
      $variables['time']['time'] .= ' - ' . $variables['time']['formatted_value2'];
    }
    if ($variables['settings']['weekly_summary'] || $variables['settings']['weekly_summary_with_label']) {
      foreach (_timefield_weekly_summary_days() as $day => $day_text) {
        $days = array();
        if ((bool) $variables['time'][$day]) {
          $days[$day] = $day_text;
        }
      }
      if ($days) {
        $variables['time']['days'] = $days;
        $variables['time']['time'] = implode(', ', $days) . ' ' . $variables['time']['time'];
      }
    }
  }
  elseif ($variables['format'] == 'duration') {

    // Encode the time elements.
    $variables['time']['value'] = check_plain($variables['time']['value']);
    $variables['time']['formatted_value'] = trim(timefield_integer_to_time($variables['settings']['display_format'], $variables['time']['value']));
    if (isset($variables['time']['value2'])) {
      $variables['time']['value2'] = check_plain($variables['time']['value2']);
      $variables['time']['formatted_value2'] = trim(timefield_integer_to_time($variables['settings']['display_format'], $variables['time']['value2']));
      $variables['time']['duration'] = timefield_time_to_duration($variables['time']['value'], $variables['time']['value2'], $variables['settings']['duration_format']);
      $variables['time']['time'] = timefield_time_to_duration($variables['time']['value'], $variables['time']['value2'], $variables['settings']['duration_format']);
    }
    else {
      $variables['time']['time'] = 0;
    }
  }
}