From 67dcd76318f9a002851f74d735233a28cce27e3a Mon Sep 17 00:00:00 2001
From: Jaap Jansma <jaap.jansma@civicoop.org>
Date: Thu, 6 Jun 2019 09:34:57 +0200
Subject: [PATCH] Changed behaviour of hidden fields on search output

---
 .../Form/AbstractSearch.php                   | 24 ++++++++++-------
 CRM/DataprocessorSearch/Form/CaseSearch.php   | 26 +++++++++++++++++++
 2 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/CRM/DataprocessorSearch/Form/AbstractSearch.php b/CRM/DataprocessorSearch/Form/AbstractSearch.php
index 95d4a391..0535e2ab 100644
--- a/CRM/DataprocessorSearch/Form/AbstractSearch.php
+++ b/CRM/DataprocessorSearch/Form/AbstractSearch.php
@@ -84,6 +84,19 @@ abstract class CRM_DataprocessorSearch_Form_AbstractSearch extends CRM_Dataproce
     return true;
   }
 
+  /**
+   * Returns an array with hidden columns
+   *
+   * @return array
+   */
+  protected function getHiddenFields() {
+    $hiddenFields = array();
+    if (!$this->isIdFieldVisible()) {
+      $hiddenFields[] = $this->getIdFieldName();
+    }
+    return $hiddenFields;
+  }
+
   /**
    * Returns the url for view of the record action
    *
@@ -278,19 +291,12 @@ abstract class CRM_DataprocessorSearch_Form_AbstractSearch extends CRM_Dataproce
    */
   protected function addColumnHeaders() {
     $sortFields = array();
-    $id_field = $this->getIdFieldName();
-    $idFieldVisible = $this->isIdFieldVisible();
+    $hiddenFields = $this->getHiddenFields();
     $columnHeaders = array();
     $sortColumnNr = 1;
     foreach($this->dataProcessorClass->getDataFlow()->getOutputFieldHandlers() as $outputFieldHandler) {
       $field = $outputFieldHandler->getOutputFieldSpecification();
-      $hiddenField = true;
-      if ($field->alias != $id_field) {
-        $hiddenField = false;
-      } elseif ($field->alias == $id_field && $idFieldVisible) {
-        $hiddenField = false;
-      }
-      if (!$hiddenField) {
+      if (!in_array($field->alias, $hiddenFields)) {
         $columnHeaders[$field->alias] = $field->title;
         $sortFields[$sortColumnNr] = array(
           'name' => $field->title,
diff --git a/CRM/DataprocessorSearch/Form/CaseSearch.php b/CRM/DataprocessorSearch/Form/CaseSearch.php
index 03ad93c7..256ab511 100644
--- a/CRM/DataprocessorSearch/Form/CaseSearch.php
+++ b/CRM/DataprocessorSearch/Form/CaseSearch.php
@@ -106,4 +106,30 @@ class CRM_DataprocessorSearch_Form_CaseSearch extends CRM_DataprocessorSearch_Fo
     return $this->_taskList;
   }
 
+  /**
+   * Returns whether the ID field is Visible
+   *
+   * @return bool
+   */
+  protected function isIdFieldVisible() {
+    if (isset($this->dataProcessorOutput['configuration']['hide_id_fields']) && $this->dataProcessorOutput['configuration']['hide_id_fields']) {
+      return false;
+    }
+    return true;
+  }
+
+  /**
+   * Returns an array with hidden columns
+   *
+   * @return array
+   */
+  protected function getHiddenFields() {
+    $hiddenFields = array();
+    if (!$this->isIdFieldVisible()) {
+      $hiddenFields[] = $this->getIdFieldName();
+      $hiddenFields[] = $this->getContactIdFieldName();
+    }
+    return $hiddenFields;
+  }
+
 }
\ No newline at end of file
-- 
GitLab