From 837afcfe808aee6b3f230b8c0c371e6c3ac82f5d Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sat, 31 Aug 2013 18:37:11 -0700 Subject: [PATCH] CRM-13027 - Fix bad results from getFields: * If entity is not extendable, then field list should be empty (not all). * If entity is blank, then throw an error. ---------------------------------------- * CRM-13027: Default getFields returns irrelevant custom-data fields http://issues.civicrm.org/jira/browse/CRM-13027 --- CRM/Core/BAO/CustomField.php | 9 +++++++++ api/v3/utils.php | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index dea4939a8c..2fab675441 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -386,6 +386,9 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { $onlySubType = FALSE, $checkPermission = TRUE ) { + if (empty($customDataType)) { + throw new CRM_Core_Exception("Cannot lookup fields for blank entity"); + } if ($customDataType && !is_array($customDataType)) { if (in_array($customDataType, CRM_Contact_BAO_ContactType::subTypes())) { @@ -475,6 +478,12 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { } } + if (empty($extends)) { + // $customDataType did not include any customizable/extendable entities. + self::$_importFields[$cacheKey] = array(); + return self::$_importFields[$cacheKey]; + } + if ($onlyParent) { $extends .= " AND $cgTable.extends_entity_column_value IS NULL AND $cgTable.extends_entity_column_id IS NULL "; } diff --git a/api/v3/utils.php b/api/v3/utils.php index ca168f90c5..e13da2483a 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -1329,7 +1329,8 @@ function _civicrm_api_get_custom_fields($entity, &$params) { $customfields = array(); $entity = _civicrm_api_get_camel_name($entity); if (strtolower($entity) == 'contact') { - $entity = CRM_Utils_Array::value('contact_type', $params); + // Use sub-type if available, otherwise stick with 'Contact' + $entity = CRM_Utils_Array::value('contact_type', $params, $entity); } $retrieveOnlyParent = FALSE; // we could / should probably test for other subtypes here - e.g. activity_type_id -- 2.25.1