I have declared this custom field in hook_views_data()
:
// The status field $data['invite']['invite_status'] = array( 'title' => t('Invite status'), 'help' => t('Provide a status field.'), 'field' => array( 'handler' => 'views_handler_status', ), 'filter' => array( 'handler' => 'views_handler_status_filter', ), );
The custom views_handler_status.inc
looks like below, if it’s relevant:
<?php /** * Field handler to present a status field. */ class views_handler_status extends views_handler_field { /** * Add required fields needed on render(). */ function construct() { parent::construct(); $this->additional_fields['expiry'] = array( 'table' => 'invite', 'field' => 'expiry', ); $this->additional_fields['canceled'] = array( 'table' => 'invite', 'field' => 'canceled', ); $this->additional_fields['joined'] = array( 'table' => 'invite', 'field' => 'joined', ); } function render($values) { $date = new DateTime(); if ($date->getTimestamp() > $values->invite_expiry) { return 'Expired'; } elseif ($values->invite_canceled == TRUE) { return 'Canceled'; } elseif (!empty($values->invite_joined)) { return 'Accepted'; } else { return 'Pending'; } } function query() { $this->add_additional_fields(); } }
and it returns the Status values for each table row as expected:
Now, I’m trying to filter in only entries with Pending
status, but nothing is working. So far I have the following content in the views_handler_status_filter.inc
file:
<?php class views_handler_status_filter extends views_handler_filter_string { public function query() { $this->ensure_my_table(); #$this->query->add_where_expression(0, "invite.status = :status", array(':status' => $this->value)); } }
As soon as I enable that commented out line, the table returns empty. I think it’s not working, because there is no actual Status column in the database, so query is confused. But if query()
in the class views_handler_status_filter extends views_handler_filter_string
is for actual database columns, then how entries could be filtered in and our based on the custom fields like Status
in this use case?