$helper($metadata);
}
- $fieldsToResolve = CRM_Utils_Array::value('get_options', $apiOptions, array());
+ $fieldsToResolve = (array) CRM_Utils_Array::value('get_options', $apiOptions, array());
foreach ($metadata as $fieldname => $fieldSpec) {
_civicrm_api3_generic_get_metadata_options($metadata, $apiRequest['entity'], $fieldname, $fieldSpec, $fieldsToResolve);
$metadata[$fieldname]['api.aliases'][] = substr($fieldname, 0, -3);
}
- if (!in_array($fieldname, $fieldsToResolve)) {
+ if (!empty($metadata[$fieldname]['options']) || !in_array($fieldname, $fieldsToResolve)) {
return;
}
}
foreach ($customfields as $key => $value) {
+ // Regular fields have a 'name' property
+ $value['name'] = 'custom_' . $key;
$customfields['custom_' . $key] = $value;
- if(in_array('custom_' . $key, $getoptions)){
- $customfields['custom_' . $key]['options'] = CRM_Core_BAO_CustomOption::valuesByID($key);
- }
+ if (in_array('custom_' . $key, $getoptions)) {
+ $customfields['custom_' . $key]['options'] = CRM_Core_BAO_CustomOption::valuesByID($key);
+ }
unset($customfields[$key]);
}
return $customfields;
return;
}
+ // Translate value into key
+ $newValue = array_search($value, $options);
+ if ($newValue !== FALSE) {
+ $value = $newValue;
+ return;
+ }
// Case-insensitive matching
$newValue = strtolower($value);
$options = array_map("strtolower", $options);
* @return (string|bool) fieldName or FALSE if the field does not exist
*/
function _civicrm_api3_api_resolve_alias($entity, $fieldName) {
+ if (strpos($fieldName, 'custom') === 0 && is_numeric($fieldName[7])) {
+ return $fieldName;
+ }
+ if ($fieldName == "{$entity}_id") {
+ return 'id';
+ }
$result = civicrm_api($entity, 'getfields', array(
'version' => 3,
'action' => 'create',
if (isset($meta[$fieldName])) {
return $meta[$fieldName]['name'];
}
- if ($fieldName == "{$entity}_id") {
- return 'id';
- }
foreach ($meta as $info) {
if ($fieldName == CRM_Utils_Array::value('uniqueName', $info)) {
return $info['name'];
'version' => 3,
'action' => 'create',
);
- $description = "Demonstrate retrieving custom field options";
+ $description = "Demonstrate retrieving metadata with custom field options";
$subfile = "GetFieldsOptions";
$fields = civicrm_api('contact', 'getfields', $getFieldsParams);
$this->documentMe($getFieldsParams, $fields, __FUNCTION__, 'ContactTest.php', $description,$subfile,'GetFields');