I've added a custom field to my view using hook_views_data:
/**
* Implements hook_views_data().
*/
function homepage_views_data() {
$data['homepage']['table']['group'] = t('Recency field');
$data['homepage']['table']['join'] = array(
// Exist in all views.
'#global' => array(),
);
$data['homepage']['recency_field'] = array(
'title' => t('Recency'),
'help' => t('Display a calculated recency date'),
'field' => array(
'handler' => 'views_handler_recency_field',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
);
return $data;
}
Right now, my field is simply returning the value of node_created. In my field handler:
/**
* Render callback handler.
*
* Return the markup that will appear in the rendered field.
*/
function render($values) {
$output = $values->node_created;
return $output;
}
I can add my custom field to a View no problem. But after adding it as a sort field, I get:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'recency_field' in 'field list'
The query looks like this:
SELECT node.title AS node_title, node.nid AS nid, node.created AS node_created, recency_field AS recency_field
FROM
{node} node
WHERE (( (node.status = '1') ))
ORDER BY recency_field ASC
Does views_handler_sort_date need to work with a real database value?
recency_field
should be in yourhomepage
table as well.