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:
views-field-output.png

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.

Comments

tim.plunkett’s picture

Component: fieldapi data » Views Data
Status: Active » Needs review
StatusFileSize
new1.09 KB

Even 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().

merlinofchaos’s picture

Right, 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.

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett
Status: Needs review » Active

Okay, the new approach is to add get_value() to both views_handler_field_prerender_list and views_handler_field_field.

aspilicious’s picture

subscribe

bojanz’s picture

get_value() already exists.

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned

get_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 :)

dawehner’s picture

StatusFileSize
new1.29 KB

This is just a patch to save the current work.

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new3.21 KB

This 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.

dawehner’s picture

Status: Needs review » Fixed

Commited to 7.x-3.x

dandaman’s picture

Umm, 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!

dawehner’s picture

Thanks for posting it here. People which might have read it before don't care about an additional maill.

rfay’s picture

Status: Fixed » Needs work

This 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.

dawehner’s picture

Status: Needs work » Postponed (maintainer needs more info)

Is this still the wrong content?

dawehner’s picture

Category: feature » bug

Update category as well

dawehner’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Status: Postponed (maintainer needs more info) » Patch (to be ported)
damienmckenna’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Status: Patch (to be ported) » Fixed

D6 is no longer supported, changing this back to D7 and closing it.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.