In order to sanely deal with core dates (timestamps) and Field API date fields, I resorted to writing my own handlers, and forcibly overriding them in hook_views_data_alter(). The both consist of a custom_render($values):
Timestamps:
class custom_handler_field_date extends views_handler_field_date {
function custom_render($values) {
return array(
'value' => array(array(
'rendered' => array('#markup' => $this->render($values)),
'raw' => array(
'value' => $values->{$this->field_alias},
),
)),
'field_name' => $this->field_alias,
);
}
}
Field API fields:
class custom_handler_field_field extends views_handler_field_field {
function custom_render($values) {
return array(
'value' => $this->get_items($values),
'field_name' => $this->definition['field_name'],
);
}
}
Here's the output:

There are two discrepancies I'm dealing with.
One is the non-existence of $this->definition['field_name'] for views_handler_field_date, and that for views_handler_field_field, $this->field_alias is the base field (nid, uid, whatever).
The other is that views_handler_field_field has the handy get_items(), while views_handler_field_date does not.
If a helper function could be added to resolve this, or changes to the definition or something, that'd be great, and I'd love to write that patch.
Or, if there is a better way to do this without needing to override the handler altogether, this can be retagged as a support request and I'd love to be schooled on the better way.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 1145770-get_value.patch | 3.21 KB | dawehner |
| #7 | 1145770.patch | 1.29 KB | dawehner |
| #1 | views-1145770-1.patch | 1.09 KB | tim.plunkett |
| views-field-output.png | 123.1 KB | tim.plunkett |
Comments
Comment #1
tim.plunkettEven this would get me 90% of the way. But I think this raises a discussion beyond just my use case, something like a views_handler_field_field::get_value().
Comment #2
merlinofchaos commentedRight, get_items() is a specific function used in rendering fields that are multi-value, so that isn't the right way.
Going the other way and making get_value() work for multi-value fields seems more useful.
Comment #3
tim.plunkettOkay, the new approach is to add get_value() to both views_handler_field_prerender_list and views_handler_field_field.
Comment #4
aspilicious commentedsubscribe
Comment #5
bojanz commentedget_value() already exists.
Comment #6
tim.plunkettget_value() is indeed part of views_handler_field, and I can't speak for views_handler_field_prerender_list, but it is completely broken for many if not all instances of views_handler_field_field.
I still want to work on this, but I'm going to unassign myself so as not to discourage anyone from posting patches :)
Comment #7
dawehnerThis is just a patch to save the current work.
Comment #8
dawehnerThis is the most weird diff i ever saw.
So what really was done is to move the code from set_items to get_value and call get_value out of set_items.
The fields are still displayed for me, but this really needs some review.
Comment #9
dawehnerCommited to 7.x-3.x
Comment #10
dandaman commentedUmm, just FYI, it seems that those of us who are using the Aggregation ("GROUP BY") features of Views 3.x are having some issues with this patch. More details here: #1194900: Missing values with aggregation sum, avg, min, max (patch included)
Thanks for your help!
Comment #11
dawehnerThanks for posting it here. People which might have read it before don't care about an additional maill.
Comment #12
rfayThis commit broke Amazon again: #1209370-19: SQL Error in All Participants.
views_handler_field_prerender_list::get_items() no longer returns the correct thing, AFAICT. Setting to needs work, but if I have to do something to fix Amazon I'll be happy to do that.
Comment #13
dawehnerIs this still the wrong content?
Comment #14
dawehnerUpdate category as well
Comment #15
dawehnermaybe #1192690: Notice: Array to string conversion in DatabaseStatementBase->execute() (line 2095 of /home/xxxx/public_html/xxx/includes/data fix the issue for you...
This patch seems to need a backport for 6.x-3.x
Comment #16
damienmckennaD6 is no longer supported, changing this back to D7 and closing it.