CRM_Utils_Hook::post(($op === 'add' ? 'create' : 'edit'), 'CustomField', $customField->id, $customField);
CRM_Utils_System::flushCache();
+ // Flush caches is not aggressive about clearing the specific cache we know we want to clear
+ // so do it manually. Ideally we wouldn't need to clear others...
+ Civi::cache('metadata')->clear();
return $customField;
}
* @return mixed
*/
protected static function getCustomFields($ctype) {
- static $customFieldCache = [];
- if (!isset($customFieldCache[$ctype])) {
+ $cacheKey = 'uf_group_custom_fields_' . $ctype;
+ if (!Civi::cache('metadata')->has($cacheKey)) {
$customFields = CRM_Core_BAO_CustomField::getFieldsForImport($ctype, FALSE, FALSE, FALSE, TRUE, TRUE);
// hack to add custom data for components
}
$addressCustomFields = CRM_Core_BAO_CustomField::getFieldsForImport('Address');
$customFields = array_merge($customFields, $addressCustomFields);
- $customFieldCache[$ctype] = [$customFields, $addressCustomFields];
+ Civi::cache('metadata')->set($cacheKey, [$customFields, $addressCustomFields]);
}
- return $customFieldCache[$ctype];
+ return Civi::cache('metadata')->get($cacheKey);
}
/**
* Associative array of property name/value.
* pairs to get profile field values
*
- * @throws API_Exception
* @return array
+ * @throws \CRM_Core_Exception
+ * @throws API_Exception
*/
function civicrm_api3_profile_get($params) {
$nonStandardLegacyBehaviour = is_numeric($params['profile_id']) ? TRUE : FALSE;
* @group headless
*/
class api_v3_ProfileTest extends CiviUnitTestCase {
+ use CRMTraits_Custom_CustomDataTrait;
protected $_profileID = 0;
/**
* Check with success.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testProfileGet() {
$profileFieldValues = $this->_createIndividualContact();
}
}
+ /**
+ * Test retrieving a profile with an address custom field in it.
+ *
+ * We are checking that there is no error.
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function testProfileGetWithAddressCustomData() {
+ $this->_createIndividualContact();
+ $this->entity = 'Address';
+ $this->createCustomGroupWithFieldOfType(['extends' => 'Address']);
+ $this->callAPISuccess('UFField', 'create', [
+ 'uf_group_id' => $this->_profileID,
+ 'field_name' => $this->getCustomFieldName('text'),
+ 'visibility' => 'Public Pages and Listings',
+ 'label' => 'My custom field',
+ 'field_type' => 'Contact',
+ ]);
+ $this->callAPISuccess('Address', 'get', ['contact_id' => $this->_contactID, 'api.Address.create' => [$this->getCustomFieldName('text') => 'my field']]);
+ $result = $this->callAPISuccess('Profile', 'get', ['profile_id' => $this->_profileID, 'contact_id' => $this->_contactID])['values'];
+ // $this->assertEquals('my field', $result[$this->getCustomFieldName('text')]);
+ }
+
/**
* Test getting multiple profiles.
*/