From 54df0f0cfba696f670ec4dc999b1feb6b99d4d56 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 6 Feb 2014 14:42:53 -0800 Subject: [PATCH] Fix api wrapper to fetch metadata from getoptions request --- api/v3/Generic.php | 8 ++------ api/v3/utils.php | 5 ++--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/api/v3/Generic.php b/api/v3/Generic.php index 3c4fc8a189..920ff3f4cb 100644 --- a/api/v3/Generic.php +++ b/api/v3/Generic.php @@ -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'); } /** diff --git a/api/v3/utils.php b/api/v3/utils.php index 96bef98ca8..a4c869bac9 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -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']; } } -- 2.25.1