Commit e6446db2 authored by colemanw's avatar colemanw

CRM-20091 - Fix return value in api.customValue.gettree

parent 5e7bd7d6
......@@ -363,14 +363,14 @@ function civicrm_api3_custom_value_gettree($params) {
unset($field['customValue']);
if (!empty($fieldInfo['customValue'])) {
$field['value'] = CRM_Utils_Array::first($fieldInfo['customValue']);
if (!$toReturn['custom_value'] || in_array('display', $toReturn['custom_value'])) {
$field['value']['display'] = CRM_Core_BAO_CustomField::displayValue($field['value']['data'], $fieldInfo);
}
foreach (array_keys($field['value']) as $key) {
if ($toReturn['custom_value'] && !in_array($key, $toReturn['custom_value'])) {
unset($field['value'][$key]);
}
}
if (!$toReturn['custom_value'] || in_array('display', $toReturn['custom_value'])) {
$field['value']['display'] = CRM_Core_BAO_CustomField::displayValue($field['value']['data'], $fieldInfo);
}
}
if (empty($params['sequential'])) {
$result[$group['name']]['fields'][$fieldInfo['name']] = $field;
......
......@@ -428,8 +428,20 @@ class api_v3_CustomValueTest extends CiviUnitTestCase {
),
));
$this->assertEquals(array('2', '3'), $tree['values']['TestGettree']['fields']['got_options']['value']['data']);
$this->assertEquals('Two, Three', $tree['values']['TestGettree']['fields']['got_options']['value']['display']);
$this->assertEquals(array('id', 'fields'), array_keys($tree['values']['TestGettree']));
// Ensure display values are returned even if data is not
$tree = $this->callAPISuccess('CustomValue', 'gettree', array(
'entity_type' => 'Contact',
'entity_id' => $contact,
'return' => array(
'custom_value.display',
),
));
$this->assertEquals('Two, Three', $tree['values']['TestGettree']['fields']['got_options']['value']['display']);
$this->assertFalse(isset($tree['values']['TestGettree']['fields']['got_options']['value']['data']));
// Verify that custom set appears for individuals even who don't have any custom data
$contact2 = $this->individualCreate();
$tree = $this->callAPISuccess('CustomValue', 'gettree', array('entity_type' => 'Contact', 'entity_id' => $contact2));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment