diff --git a/CRM/Contact/BAO/Query/Hook.php b/CRM/Contact/BAO/Query/Hook.php index 01e68fb666e1..1d611578c3ab 100644 --- a/CRM/Contact/BAO/Query/Hook.php +++ b/CRM/Contact/BAO/Query/Hook.php @@ -65,6 +65,23 @@ public function &getFields() { return $extFields; } + /** + * Get the fields that are available in the 'contact context'. + * + * For example exporting contacts should not include fields for grants etc. + * + * @return array + */ + public function getContactFields(): array { + $extFields = []; + foreach ($this->getSearchQueryObjects() as $obj) { + // Get Fields is ambiguous about the + $fields = method_exists($obj, 'getContactFields') ? $obj->getContactFields() : $obj->getFields(); + $extFields = array_merge($extFields, $fields); + } + return $extFields; + } + /** * @param $apiEntities * @param $fieldOptions diff --git a/CRM/Core/BAO/Mapping.php b/CRM/Core/BAO/Mapping.php index 373c61a9f039..ee1ade7d58c5 100644 --- a/CRM/Core/BAO/Mapping.php +++ b/CRM/Core/BAO/Mapping.php @@ -611,7 +611,10 @@ public static function getBasicFields($mappingType) { else { $contactFields = CRM_Contact_BAO_Contact::exportableFields($contactType, FALSE, TRUE); } - $contactFields = array_merge($contactFields, CRM_Contact_BAO_Query_Hook::singleton()->getFields()); + // It's unclear when we would want this but.... see + // https://lab.civicrm.org/dev/core/-/issues/3069 for when we don't.... + $contactFields = array_merge($contactFields, CRM_Contact_BAO_Query_Hook::singleton() + ->getContactFields()); // Exclude the address options disabled in the Address Settings $fields[$contactType] = CRM_Core_BAO_Address::validateAddressOptions($contactFields); diff --git a/ext/civigrant/CRM/Grant/BAO/Query.php b/ext/civigrant/CRM/Grant/BAO/Query.php index 9c59f40125d2..5247bac153b1 100644 --- a/ext/civigrant/CRM/Grant/BAO/Query.php +++ b/ext/civigrant/CRM/Grant/BAO/Query.php @@ -17,16 +17,25 @@ class CRM_Grant_BAO_Query extends CRM_Contact_BAO_Query_Interface { /** - * Unused. + * Get available fields. * - * This function is meant to return extra contact fields, but grants are not contacts. + * Important for exports & relative date filters. * * @return array */ public function &getFields() { - $fields = []; - return $fields; - // return CRM_Grant_BAO_Grant::exportableFields(); + return CRM_Grant_BAO_Grant::exportableFields(); + } + + /** + * Get the fields that are available in the 'contact context'. + * + * For example exporting contacts should not include fields for grants etc. + * + * @return array + */ + public function getContactFields(): array { + return []; } /**