Skip to content

Commit

Permalink
Merge pull request #10540 from colemanw/CRM-20091
Browse files Browse the repository at this point in the history
CRM-20091 - Fix return value in api.customValue.gettree
  • Loading branch information
colemanw authored Jun 21, 2017
2 parents 5e7bd7d + e6446db commit b132aad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions api/v3/CustomValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions tests/phpunit/api/v3/CustomValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,20 @@ public function testGettree() {
),
));
$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));
Expand Down

0 comments on commit b132aad

Please sign in to comment.