X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fv3%2FCustomValue.php;h=a524d615715938c963f17330f8e55300e9872196;hb=ac439a0617d2a9d7bf661b615928a6f50c3ad5a9;hp=48c3f93b858367cfae24c2a0eb2870ed11916841;hpb=e71360126e438a313d4ab86524a462e01e0efdfa;p=civicrm-core.git diff --git a/api/v3/CustomValue.php b/api/v3/CustomValue.php index 48c3f93b85..a524d61571 100644 --- a/api/v3/CustomValue.php +++ b/api/v3/CustomValue.php @@ -1,27 +1,11 @@ 'Entity Id', + 'description' => 'Id of entity', + 'type' => CRM_Utils_Type::T_INT, + 'api.required' => 1, + ]; + $spec['custom_field_id'] = [ + 'title' => 'Custom Field ID', + 'description' => 'Id of custom field', + 'type' => CRM_Utils_Type::T_INT, + 'api.required' => 1, + ]; + $spec['custom_field_value'] = [ + 'title' => 'Custom Field value', + 'description' => 'Specify the value of the custom field to return as displayed value', + 'type' => CRM_Utils_Type::T_STRING, + 'api.required' => 0, + ]; +} + +/** + * CustomValue.getdisplayvalue API + * + * @param array $params + * + * @return array API result + * @throws \CiviCRM_API3_Exception + */ +function civicrm_api3_custom_value_getdisplayvalue($params) { + if (empty($params['custom_field_value'])) { + $params['custom_field_value'] = civicrm_api3('CustomValue', 'getsingle', [ + 'return' => ["custom_{$params['custom_field_id']}"], + 'entity_id' => $params['entity_id'], + ]); + $params['custom_field_value'] = $params['custom_field_value']['latest']; + } + $values[$params['custom_field_id']]['display'] = CRM_Core_BAO_CustomField::displayValue($params['custom_field_value'], $params['custom_field_id'], CRM_Utils_Array::value('entity_id', $params)); + $values[$params['custom_field_id']]['raw'] = $params['custom_field_value']; + return civicrm_api3_create_success($values, $params, 'CustomValue', 'getdisplayvalue'); +}