if ($fkDAO->find(TRUE)) {
$this->$dbName = $fkDAO->id;
}
- $fkDAO->free();
}
elseif (in_array($FKClassName, CRM_Core_DAO::$_testEntitiesToSkip)) {
$depObject = new $FKClassName();
$depObject->find(TRUE);
$this->$dbName = $depObject->id;
- $depObject->free();
}
elseif ($daoName == 'CRM_Member_DAO_MembershipType' && $fieldName == 'member_of_contact_id') {
// FIXME: the fields() metadata is not specific enough
$depObject = CRM_Core_DAO::createTestObject($FKClassName, ['contact_type' => 'Organization']);
$this->$dbName = $depObject->id;
- $depObject->free();
}
else {
//if it is required we need to generate the dependency object first
$depObject = CRM_Core_DAO::createTestObject($FKClassName, CRM_Utils_Array::value($dbName, $params, 1));
$this->$dbName = $depObject->id;
- $depObject->free();
}
}
* @return string
* @throws Exception
*/
- public static function composeQuery($query, $params, $abort = TRUE) {
+ public static function composeQuery($query, $params = [], $abort = TRUE) {
$tr = [];
foreach ($params as $key => $item) {
if (is_numeric($key)) {
if (!$blockCopyofCustomValues) {
$newObject->copyCustomFields($object->id, $newObject->id);
}
- CRM_Utils_Hook::post('create', CRM_Core_DAO_AllCoreTables::getBriefName($daoName), $newObject->id, $newObject);
+ CRM_Utils_Hook::post('create', CRM_Core_DAO_AllCoreTables::getBriefName(str_replace('_BAO_', '_DAO_', $daoName)), $newObject->id, $newObject);
}
return $newObject;
}
}
self::appendCustomTablesExtendingContacts($contactReferences);
+ self::appendCustomContactReferenceFields($contactReferences);
// FixME for time being adding below line statically as no Foreign key constraint defined for table 'civicrm_entity_tag'
$contactReferences['civicrm_entity_tag'][] = 'entity_id';
$customValueTables = CRM_Core_BAO_CustomGroup::getAllCustomGroupsByBaseEntity('Contact');
$customValueTables->find();
while ($customValueTables->fetch()) {
- $cidRefs[$customValueTables->table_name] = ['entity_id'];
+ $cidRefs[$customValueTables->table_name][] = 'entity_id';
+ }
+ }
+
+ /**
+ * Add custom ContactReference fields to the list of contact references
+ *
+ * This includes active and inactive fields/groups
+ *
+ * @param array $cidRefs
+ *
+ * @throws \CiviCRM_API3_Exception
+ */
+ public static function appendCustomContactReferenceFields(&$cidRefs) {
+ $fields = civicrm_api3('CustomField', 'get', [
+ 'return' => ['column_name', 'custom_group_id.table_name'],
+ 'data_type' => 'ContactReference',
+ ])['values'];
+ foreach ($fields as $field) {
+ $cidRefs[$field['custom_group_id.table_name']][] = $field['column_name'];
}
}