From b62bc939156b89499e10b29664bf4c09c6bf2412 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 16 Jun 2015 21:41:06 +1200 Subject: [PATCH] CRM-16699 retrieve custom fields with subtypes from api --- CRM/Core/BAO/CustomGroup.php | 11 +++++++++-- api/v3/utils.php | 7 +++++-- tests/phpunit/api/v3/ActivityTest.php | 24 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index fadeae8dc1..af3974f6e1 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -324,6 +324,10 @@ class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup { * @param string $subName * @param bool $fromCache * @param bool $onlySubType + * Only return specified subtype or return specified subtype + unrestricted fields. + * @param bool $returnAll + * Do not restrict by subtype at all. (The parameter feels a bit cludgey but is only used from the + * api - through which it is properly tested - so can be refactored with some comfort.) * * @return array * The returned array is keyed by group id and has the custom group table fields @@ -343,7 +347,8 @@ class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup { $subType = NULL, $subName = NULL, $fromCache = TRUE, - $onlySubType = NULL + $onlySubType = NULL, + $returnAll = FALSE ) { if ($entityID) { $entityID = CRM_Utils_Type::escape($entityID, 'Integer'); @@ -474,8 +479,10 @@ WHERE civicrm_custom_group.is_active = 1 WHERE civicrm_custom_group.is_active = 1 AND civicrm_custom_field.is_active = 1 AND civicrm_custom_group.extends IN ($in) - AND civicrm_custom_group.extends_entity_column_value IS NULL "; + if (!$returnAll) { + $strWhere .= "AND civicrm_custom_group.extends_entity_column_value IS NULL"; + } } $params = array(); diff --git a/api/v3/utils.php b/api/v3/utils.php index e0abd13935..08536a9850 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -1413,8 +1413,11 @@ function _civicrm_api3_custom_data_get(&$returnArray, $entity, $entity_id, $grou CRM_Core_DAO::$_nullObject, $entity_id, $groupID, - $subType, - $subName + NULL, + $subName, + TRUE, + NULL, + TRUE ); $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, CRM_Core_DAO::$_nullObject); $customValues = array(); diff --git a/tests/phpunit/api/v3/ActivityTest.php b/tests/phpunit/api/v3/ActivityTest.php index 589a2fd742..5f671247ec 100644 --- a/tests/phpunit/api/v3/ActivityTest.php +++ b/tests/phpunit/api/v3/ActivityTest.php @@ -387,6 +387,30 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $this->customGroupDelete($ids['custom_group_id']); } + /** + * Test civicrm_activity_create() with valid parameters and custom data. + */ + public function testActivityCreateCustomSubType() { + $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); + $this->callAPISuccess('CustomGroup', 'create', array( + 'extends_entity_column_value' => $this->test_activity_type_value, + 'id' => $ids['custom_group_id'], + 'extends' => 'Activity', + 'is_active' => TRUE, + )); + $params = $this->_params; + $params['custom_' . $ids['custom_field_id']] = "custom string"; + $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); + $result = $this->callAPISuccess($this->_entity, 'get', array( + 'return.custom_' . $ids['custom_field_id'] => 1, + 'id' => $result['id'], + )); + $this->assertEquals("custom string", $result['values'][$result['id']]['custom_' . $ids['custom_field_id']]); + + $this->customFieldDelete($ids['custom_field_id']); + $this->customGroupDelete($ids['custom_group_id']); + } + /** * Test civicrm_activity_create() with valid parameters and custom data. */ -- 2.25.1