+/**
+ * Function to call getfields from api wrapper. This function ensures that settings that could alter
+ * getfields output (e.g. action for all api & profile_id for profile api ) are consistently passed in.
+ *
+ * We check whether the api call is 'getfields' because if getfields is being called we return an empty array
+ * as no alias swapping, validation or default filling is done on getfields & we want to avoid a loop
+ *
+ * @todo other output modifiers include contact_type
+ *
+ * @param array $apiRequest
+ * @return getfields output
+ */
+function _civicrm_api3_api_getfields(&$apiRequest) {
+ if (strtolower($apiRequest['action'] == 'getfields')) {
+ // the main param getfields takes is 'action' - however this param is not compatible with REST
+ // so we accept 'api_action' as an alias of action on getfields
+ if (CRM_Utils_Array::value('api_action', $apiRequest['params'])) {
+ // $apiRequest['params']['action'] = $apiRequest['params']['api_action'];
+ // unset($apiRequest['params']['api_action']);
+ }
+ return array('action' => array('api.aliases' => array('api_action')));
+ }
+ $getFieldsParams = array('action' => $apiRequest['action']);
+ $entity = $apiRequest['entity'];
+ if($entity == 'profile' && array_key_exists('profile_id', $apiRequest['params'])) {
+ $getFieldsParams['profile_id'] = $apiRequest['params']['profile_id'];
+ }
+ $fields = civicrm_api3($entity, 'getfields', $getFieldsParams);
+ return $fields['values'];
+}
+