diff --git a/modules/views/civicrm/civicrm_handler_filter_contact_ref.inc b/modules/views/civicrm/civicrm_handler_filter_contact_ref.inc index a8a26ef75..3cfa481b0 100644 --- a/modules/views/civicrm/civicrm_handler_filter_contact_ref.inc +++ b/modules/views/civicrm/civicrm_handler_filter_contact_ref.inc @@ -43,13 +43,36 @@ class civicrm_handler_filter_contact_ref extends views_handler_filter_string { $this->filterContactRef($field); } + /** + * @param string $field + */ + public function op_contact_id($field) { + $this->operator = '='; + $this->filterContactRef($field, 'id'); + } + + /** + * Add Contact ID to the list of operators. + */ + public function operators() { + $op = parent::operators(); + $op['contact_id'] = [ + 'title' => t('Contact ID'), + 'short' => t('contact_id'), + 'method' => 'op_contact_id', + 'values' => 1, + ]; + return $op; + } + /** * Adds where clause to the view query to filter - * by contact sort_name instead of id. + * by contact sort_name OR id based on operator selected. * * @param string $field + * @param string $fieldName */ - public function filterContactRef($field) { + public function filterContactRef($field, $fieldName = 'sort_name') { if (!empty($this->value)) { $op = $this->operator; if ($this->operator != '=' && $this->operator != '!=') { @@ -58,7 +81,7 @@ class civicrm_handler_filter_contact_ref extends views_handler_filter_string { } $contacts = db_select('civicrm_contact', 'cc') ->fields('cc', array('id')) - ->condition('cc.sort_name', $this->value, $op); + ->condition("cc.{$fieldName}", $this->value, $op); $this->query->add_where($this->options['group'], $field, $contacts, 'IN'); }