Fixes a bug where contact.get does not retrieve results if a custom field is requested and an activity custom field exists
This bug came about because a recent fix made metadata more consistent but it turns out this class was filtering the
metadata by the passed in - and then iterating through the metadata. Now it iterates the ids instead.
return;
}
- foreach ($this->_fields as $id => $field) {
+ foreach (array_keys($this->_ids) as $id) {
+ $field = $this->_fields[$id];
$name = $field['table_name'];
$fieldName = 'custom_' . $field['id'];
$this->_select["{$name}_id"] = "{$name}.id as {$name}_id";
}
$this->_tables[$name] = "\nLEFT JOIN $name ON $name.entity_id = $joinTable.id";
-
- if (!empty($this->_ids[$id])) {
- $this->_whereTables[$name] = $this->_tables[$name];
- }
+ $this->_whereTables[$name] = $this->_tables[$name];
if ($joinTable) {
$joinClause = 1;
* @param array $groupParams
* @param string $customFieldType
*
+ * @param string $identifier
+ *
* @throws \CRM_Core_Exception
*/
- public function createCustomGroupWithFieldOfType($groupParams = [], $customFieldType = 'text') {
+ public function createCustomGroupWithFieldOfType($groupParams = [], $customFieldType = 'text', $identifier = '') {
if ($customFieldType !== 'text') {
throw new CRM_Core_Exception('we have not yet extracted other custom field types from createCustomFieldsOfAllTypes, Use consistent syntax when you do');
}
- $groupParams['title'] = empty($groupParams['title']) ? 'Group with field ' . $customFieldType : $groupParams['title'];
+ $groupParams['title'] = empty($groupParams['title']) ? $identifier . 'Group with field ' . $customFieldType : $groupParams['title'];
$this->createCustomGroup($groupParams);
$customField = $this->createTextCustomField(['custom_group_id' => $this->ids['CustomGroup'][$groupParams['title']]]);
- $this->ids['CustomField'][$customFieldType] = $customField['id'];
+ $this->ids['CustomField'][$identifier . $customFieldType] = $customField['id'];
}
/**
$this->customGroupDelete($ids['custom_group_id']);
}
+ /**
+ * Tests that using 'return' with a custom field not of type contact does not inappropriately filter.
+ *
+ * https://lab.civicrm.org/dev/core/issues/1025
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function testGetWithCustomOfActivityType() {
+ $this->createCustomGroupWithFieldOfType(['extends' => 'Activity']);
+ $this->createCustomGroupWithFieldOfType(['extends' => 'Contact'], 'text', 'contact_');
+ $contactID = $this->individualCreate();
+ $this->callAPISuccessGetSingle('Contact', ['id' => $contactID, 'return' => ['external_identifier', $this->getCustomFieldName('contact_text')]]);
+ }
+
/**
* Check with complete array + custom field.
*