diff --git a/CRM/Contact/BAO/Query/Hook.php b/CRM/Contact/BAO/Query/Hook.php index 01e68fb666e1faf5707e4d5337379351e362d15d..1d611578c3ab6b0c48e9f14805ebeaa0335a8dd4 100644 --- a/CRM/Contact/BAO/Query/Hook.php +++ b/CRM/Contact/BAO/Query/Hook.php @@ -65,6 +65,23 @@ class CRM_Contact_BAO_Query_Hook { 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 373c61a9f039075a0980ea2ddef8109496038343..ee1ade7d58c5d60b57f4ecc5d43ef6eadd24a64e 100644 --- a/CRM/Core/BAO/Mapping.php +++ b/CRM/Core/BAO/Mapping.php @@ -611,7 +611,10 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping implements \Civi\Core\Ho 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 9c59f40125d21a67fe5215cb302054df2839cc50..5247bac153b1c5bbb0fcc79fbb9700356c54efea 100644 --- a/ext/civigrant/CRM/Grant/BAO/Query.php +++ b/ext/civigrant/CRM/Grant/BAO/Query.php @@ -17,16 +17,25 @@ use CRM_Grant_ExtensionUtil as E; 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 []; } /**