function TimefieldHandlerFieldTimefield::add_self_tokens in Timefield 7
Add any special tokens this field might use for itself.
This method is intended to be overridden by items that generate fields as a list. For example, the field that displays all terms on a node might have tokens for the tid and the term.
By convention, tokens should follow the format of [token-subtoken] where token is the field ID and subtoken is the field. If the field ID is terms, then the tokens might be [terms-tid] and [terms-name].
Overrides views_handler_field_field::add_self_tokens
File
- views/
timefield_handler_field_timefield.inc, line 12 - Contains the duration field handler.
Class
- TimefieldHandlerFieldTimefield
- @file Contains the duration field handler.
Code
function add_self_tokens(&$tokens, $item) {
if (!empty($item['raw']['value_formatted'])) {
$time = new DateTime($item['raw']['value_formatted']);
$tokens['[' . $this->options['id'] . '-value-hour' . ']'] = $time
->format('g');
$tokens['[' . $this->options['id'] . '-value-24hour' . ']'] = $time
->format('G');
$tokens['[' . $this->options['id'] . '-value-minute' . ']'] = $time
->format('i');
$tokens['[' . $this->options['id'] . '-value-ampm' . ']'] = $time
->format('a');
$tokens['[' . $this->options['id'] . '-value-upper-ampm' . ']'] = $time
->format('A');
if ($this->field_info['settings']['totime'] && !empty($item['raw']['value2_formatted'])) {
$time = new DateTime($item['raw']['value2_formatted']);
$tokens['[' . $this->options['id'] . '-value2-hour' . ']'] = $time
->format('g');
$tokens['[' . $this->options['id'] . '-value2-24hour' . ']'] = $time
->format('G');
$tokens['[' . $this->options['id'] . '-value2-minute' . ']'] = $time
->format('i');
$tokens['[' . $this->options['id'] . '-value2-ampm' . ']'] = $time
->format('a');
$tokens['[' . $this->options['id'] . '-value2-upper-ampm' . ']'] = $time
->format('A');
}
if ($this->field_info['settings']['weekly_summary']) {
foreach (_timefield_weekly_summary_days() as $day => $daytext) {
if (!empty($item['raw'][$day])) {
$tokens['[' . $this->options['id'] . '-' . $day . ']'] = $item['raw'][$day] ? $daytext : '';
}
}
}
}
}