CRM-13027 - Fix bad results from getFields:
[civicrm-core.git] / api / v3 / utils.php
index 149a7fb34b02ac8d816ebe18f3f1619644e89e69..e13da2483a6253b70ad9bf1304fc7fae36daa024 100644 (file)
@@ -1220,9 +1220,7 @@ function _civicrm_api3_generic_replace($entity, $params) {
     }
 
     // Extract the keys -- somewhat scary, don't think too hard about it
-    $baseParams = $params;
-    unset($baseParams['values']);
-    unset($baseParams['sequential']);
+    $baseParams = _civicrm_api3_generic_replace_base_params($params);
 
     // Lookup pre-existing records
     $preexisting = civicrm_api($entity, 'get', $baseParams, $params);
@@ -1275,6 +1273,14 @@ function _civicrm_api3_generic_replace($entity, $params) {
   }
 }
 
+function _civicrm_api3_generic_replace_base_params($params) {
+  $baseParams = $params;
+  unset($baseParams['values']);
+  unset($baseParams['sequential']);
+  unset($baseParams['options']);
+  return $baseParams;
+}
+
 /**
  * returns fields allowable by api
  * @param $entity string Entity to query
@@ -1323,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