Support custom fields CRM-12464
authorColeman Watts <coleman@civicrm.org>
Sun, 12 May 2013 20:40:23 +0000 (13:40 -0700)
committerColeman Watts <coleman@civicrm.org>
Thu, 30 May 2013 05:14:05 +0000 (22:14 -0700)
----------------------------------------
* CRM-12464: Add PseudoConstants to Schema Metadata
  http://issues.civicrm.org/jira/browse/CRM-12464

CRM/Core/PseudoConstant.php
api/v3/Generic.php

index bad70b4eee3cc4b56053429d1597a6e6c78b65ef..06055036670f86751afd901a858fca1fd4a9be3b 100644 (file)
@@ -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'])) {
index 6ad82b3098c7c84e61fbb7ab72221f056aa5affd..e86bd43d63c53babfca87b3b1f6b6bbc7a5a0191 100644 (file)
@@ -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':