From 4e5340cac10c05a3a21d8301e252958a40f702fd Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Mon, 22 Apr 2019 12:46:04 +0530 Subject: [PATCH] dev/drupal#58 - Add Contact ID operator to the contact reference filter added in drupal view --- .../civicrm_handler_filter_contact_ref.inc | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) 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'); }