function theme_hms_natural_language in HMS Field 7
Theme hms_natural_language
TODO: Investigate running since options (see theme_hms) Would be cool if we can also make this format a 'Forrest Gump' format.
File
- ./
hms_field.module, line 335 - Provides an hms_field functionality.
Code
function theme_hms_natural_language($variables) {
$labels = _hms_factor_map(TRUE);
// Assign keyed values array.
$values = array_combine(explode(':', $variables['format']), explode(':', _hms_seconds_to_formatted($variables['value'], $variables['format'], TRUE)));
// Spit out HTML per value (only when value > 0).
$html = array();
foreach ($values as $key => $val) {
if ($val != 0) {
$html[] = '<span class="' . drupal_clean_css_identifier($labels[$key]['label multiple']) . '">' . format_plural($val, '@count ' . $labels[$key]['label single'], '@count ' . $labels[$key]['label multiple']) . '</span>';
}
}
// Serial commas - and
$and = $comma = t($variables['separator']);
if (isset($variables['last_separator']) && strlen($variables['last_separator'])) {
$and = t($variables['last_separator']);
}
switch (count($html)) {
case 0:
case 1:
return reset($html);
default:
$last = array_pop($html);
return implode($comma, $html) . $and . $last;
}
}