Fix api wrapper to fetch metadata from getoptions request
authorColeman Watts <coleman@civicrm.org>
Thu, 6 Feb 2014 22:42:53 +0000 (14:42 -0800)
committerColeman Watts <coleman@civicrm.org>
Fri, 7 Feb 2014 22:08:06 +0000 (14:08 -0800)
api/v3/Generic.php
api/v3/utils.php

index 3c4fc8a189947e6261c6931d4ecbd2533f9520ec..920ff3f4cba9301e1f780b1e741babe7facda7c9 100644 (file)
@@ -40,13 +40,9 @@ function civicrm_api3_generic_getfields($apiRequest) {
   $action       = strtolower(CRM_Utils_Array::value('action', $apiRequest['params']));
   $sequential = empty($apiRequest['params']) ? 0 : 1;
   $apiOptions = CRM_Utils_Array::value('options', $apiRequest['params'], array());
-  if ($action == 'getvalue' || $action == 'getvalue' || $action == 'getcount') {
+  if (!$action || $action == 'getvalue' || $action == 'getcount') {
     $action = 'get';
   }
-
-  if (empty($action)) {
-    $action='get';
-  }
   // determines whether to use unique field names - seem comment block above
   $unique = TRUE;
   if (empty($apiOptions) && isset($results[$entity . $subentity]) && isset($action, $results[$entity . $subentity])
@@ -239,7 +235,7 @@ function civicrm_api3_generic_getoptions($apiRequest) {
       $output[] = array('key' => $key, 'value' => $val);
     }
   }
-  return civicrm_api3_create_success($output);
+  return civicrm_api3_create_success($output, $apiRequest['params'], $apiRequest['entity'], 'getoptions');
 }
 
 /**
index 96bef98ca8bd6a61416b27a17b0e015ff81f780d..a4c869bac9941da04f7909f6420c03abd271caa1 100644 (file)
@@ -181,8 +181,7 @@ function civicrm_api3_create_error($msg, $data = array(), &$dao = NULL) {
  *
  * @return array $result
  */
-function civicrm_api3_create_success($values = 1, $params = array(
-  ), $entity = NULL, $action = NULL, &$dao = NULL, $extraReturnValues = array()) {
+function civicrm_api3_create_success($values = 1, $params = array(), $entity = NULL, $action = NULL, &$dao = NULL, $extraReturnValues = array()) {
   $result = array();
   $result['is_error'] = 0;
   //lets set the ['id'] field if it's not set & we know what the entity is
@@ -256,7 +255,7 @@ function civicrm_api3_create_success($values = 1, $params = array(
   if(!empty($params['options']['metadata'])) {
     // we've made metadata an array but only supporting 'fields' atm
     if(in_array('fields', $params['options']['metadata'])) {
-      $fields = civicrm_api3($entity, 'getfields', array('action' => $action));
+      $fields = civicrm_api3($entity, 'getfields', array('action' => substr($action, 0, 3) == 'get' ? 'get' : 'create'));
       $result['metadata']['fields'] = $fields['values'];
     }
   }