CRM-15646 - api.setvalue: Add support for custom fields
authorColeman Watts <coleman@civicrm.org>
Tue, 25 Nov 2014 17:59:41 +0000 (12:59 -0500)
committerColeman Watts <coleman@civicrm.org>
Tue, 25 Nov 2014 19:07:45 +0000 (14:07 -0500)
api/v3/Generic/Setvalue.php

index cae77e1193f1873081198701da9a5be62a0677dc..53c136d8509c64bad1113733fb158e0abb1078b9 100644 (file)
@@ -72,7 +72,15 @@ function civicrm_api3_generic_setValue($apiRequest) {
   $params = array('id' => $id, $field => $value);
   CRM_Utils_Hook::pre('edit', $entity, $id, $params);
 
-  if (CRM_Core_DAO::setFieldValue($dao_name, $id, $field, $params[$field])) {
+  // Custom fields
+  if (strpos($field, 'custom_') === 0) {
+    CRM_Utils_Array::crmReplaceKey($params, 'id', 'entityID');
+    CRM_Core_BAO_CustomValueTable::setValues($params);
+    CRM_Utils_Hook::post('edit', $entity, $id, CRM_Core_DAO::$_nullObject);
+    return civicrm_api3_create_success($params);
+  }
+  // Core fields
+  elseif (CRM_Core_DAO::setFieldValue($dao_name, $id, $field, $params[$field])) {
     $entityDAO = new $dao_name();
     $entityDAO->copyValues($params);
     CRM_Utils_Hook::post('edit', $entity, $entityDAO->id, $entityDAO);