From f2b53f2699051f6066b579da62b17a939e67119c Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 12 May 2013 13:40:23 -0700 Subject: [PATCH] Support custom fields CRM-12464 ---------------------------------------- * CRM-12464: Add PseudoConstants to Schema Metadata http://issues.civicrm.org/jira/browse/CRM-12464 --- CRM/Core/PseudoConstant.php | 16 +++++++++++++++- api/v3/Generic.php | 9 +-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index bad70b4eee..0605503667 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -219,6 +219,21 @@ class CRM_Core_PseudoConstant { * @static */ public static function get($daoName, $fieldName, $params = array()) { + $flip = !empty($params['flip']); + + // Custom fields are not in the schema + if (strpos($fieldName, 'custom') === 0) { + $dao = new CRM_Core_DAO_CustomField; + $dao->id = (int) substr($fieldName, 7); + $dao->find(TRUE); + $customField = (array) $dao; + $dao->free(); + $output = array(); + CRM_Core_BAO_CustomField::buildOption($customField, $output); + return $flip ? array_flip($output) : $output; + } + + // Core field: load schema $dao = new $daoName; $fields = $dao->fields(); $fieldKeys = $dao->fieldKeys(); @@ -228,7 +243,6 @@ class CRM_Core_PseudoConstant { return FALSE; } $fieldSpec = $fields[$fieldKey]; - $flip = !empty($params['flip']); // If the field is an enum, explode the enum definition and return the array. if (isset($fieldSpec['enumValues'])) { diff --git a/api/v3/Generic.php b/api/v3/Generic.php index 6ad82b3098..e86bd43d63 100644 --- a/api/v3/Generic.php +++ b/api/v3/Generic.php @@ -55,13 +55,7 @@ function civicrm_api3_generic_getfields($apiRequest) { switch ($action) { case 'getfields': $values = _civicrm_api_get_fields($entity, false, $apiRequest['params']); - $results[$entity][$action] = civicrm_api3_create_success($values, - $apiRequest['params'], $entity, 'getfields' - ); - return $results[$entity][$action]; - - case 'getfields': - return civicrm_api3_create_success(_civicrm_api_get_fields($apiRequest['entity'])); + return civicrm_api3_create_success($values, $apiRequest['params'], $entity, 'getfields'); case 'create': case 'update': case 'replace': @@ -84,7 +78,6 @@ function civicrm_api3_generic_getfields($apiRequest) { // inconsistency $metadata['id']['api.aliases'] = array($lcase_entity . '_id'); } - break; case 'delete': -- 2.25.1