CRM-16699 retrieve custom fields with subtypes from api
authorEileen McNaughton <eileen@fuzion.co.nz>
Tue, 16 Jun 2015 09:41:06 +0000 (21:41 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Tue, 16 Jun 2015 09:41:06 +0000 (21:41 +1200)
CRM/Core/BAO/CustomGroup.php
api/v3/utils.php
tests/phpunit/api/v3/ActivityTest.php

index fadeae8dc136c5ede55606227d13f1284db8ecc1..af3974f6e1a58140e2655da6f261b9efbeb6d64f 100644 (file)
@@ -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();
index e0abd13935cdf532dd0cfa8b8486d7c1686627fa..08536a9850266b0ef607e09cf7d8cbb4afe31f57 100644 (file)
@@ -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();
index 589a2fd742deda780295b60cf024b927986b87be..5f671247ec9c76f48b3c07aa394ac1e7d4a6dd66 100644 (file)
@@ -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.
    */