3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * This api exposes CiviCRM profiles.
31 * Profiles are collections of fields used as forms, listings, search columns, etc.
33 * @package CiviCRM_APIv3
37 * Retrieve Profile field values.
39 * NOTE this api is not standard & since it is tested we need to honour that
40 * but the correct behaviour is for it to return an id indexed array as this supports
41 * multiple instances - if a single profile is passed in we will not return a normal api result array
42 * in order to avoid breaking code. (This could still be confusing :-( but we have to keep the tested behaviour working
44 * Note that if contact_id is empty an array of defaults is returned
46 * @param array $params
47 * Associative array of property name/value.
48 * pairs to get profile field values
51 * @throws \CRM_Core_Exception
52 * @throws API_Exception
54 function civicrm_api3_profile_get($params) {
55 $nonStandardLegacyBehaviour = is_numeric($params['profile_id']) ?
TRUE : FALSE;
56 if (!empty($params['check_permissions']) && !empty($params['contact_id']) && !1 === civicrm_api3('contact', 'getcount', ['contact_id' => $params['contact_id'], 'check_permissions' => 1])) {
57 throw new API_Exception('permission denied');
59 $profiles = (array) $params['profile_id'];
61 $ufGroupBAO = new CRM_Core_BAO_UFGroup();
62 foreach ($profiles as $profileID) {
63 $profileID = _civicrm_api3_profile_getProfileID($profileID);
64 $values[$profileID] = [];
65 if (strtolower($profileID) == 'billing') {
66 $values[$profileID] = _civicrm_api3_profile_getbillingpseudoprofile($params);
69 if (!CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_active')) {
70 throw new API_Exception('Invalid value for profile_id : ' . $profileID);
73 $isContactActivityProfile = CRM_Core_BAO_UFField
::checkContactActivityProfileType($profileID);
75 $profileFields = CRM_Core_BAO_UFGroup
::getFields($profileID,
82 empty($params['check_permissions']) ?
FALSE : TRUE,
84 CRM_Core_Permission
::EDIT
87 if ($isContactActivityProfile) {
88 civicrm_api3_verify_mandatory($params, NULL, ['activity_id']);
90 $errors = CRM_Profile_Form
::validateContactActivityProfile($params['activity_id'],
91 $params['contact_id'],
94 if (!empty($errors)) {
95 throw new API_Exception(array_pop($errors));
98 $contactFields = $activityFields = [];
99 foreach ($profileFields as $fieldName => $field) {
100 if (CRM_Utils_Array
::value('field_type', $field) == 'Activity') {
101 $activityFields[$fieldName] = $field;
104 $contactFields[$fieldName] = $field;
105 // we should return 'Primary' with & without capitalisation. it is more consistent with api to not
106 // capitalise, but for form support we need it for now. Hopefully we can move away from it
107 $contactFields[strtolower($fieldName)] = $field;
111 $ufGroupBAO->setProfileDefaults($params['contact_id'], $contactFields, $values[$profileID], TRUE);
113 if ($params['activity_id']) {
114 $ufGroupBAO->setComponentDefaults($activityFields, $params['activity_id'], 'Activity', $values[$profileID], TRUE);
117 elseif (!empty($params['contact_id'])) {
118 $ufGroupBAO->setProfileDefaults($params['contact_id'], $profileFields, $values[$profileID], TRUE);
119 foreach ($values[$profileID] as $fieldName => $field) {
120 // we should return 'Primary' with & without capitalisation. it is more consistent with api to not
121 // capitalise, but for form support we need it for now. Hopefully we can move away from it
122 $values[$profileID][strtolower($fieldName)] = $field;
126 $values[$profileID] = array_fill_keys(array_keys($profileFields), '');
129 if ($nonStandardLegacyBehaviour) {
130 $result = civicrm_api3_create_success();
131 $result['values'] = $values[$profileID];
135 return civicrm_api3_create_success($values, $params, 'Profile', 'Get');
140 * Adjust profile get function metadata.
142 * @param array $params
144 function _civicrm_api3_profile_get_spec(&$params) {
145 $params['profile_id']['api.required'] = TRUE;
146 $params['profile_id']['title'] = 'Profile ID';
147 $params['contact_id']['description'] = 'If no contact is specified an array of defaults will be returned';
148 $params['contact_id']['title'] = 'Contact ID';
152 * Submit a set of fields against a profile.
154 * Note choice of submit versus create is discussed CRM-13234 & related to the fact
155 * 'profile' is being treated as a data-entry entity
157 * @param array $params
159 * @throws API_Exception
163 function civicrm_api3_profile_submit($params) {
164 $profileID = _civicrm_api3_profile_getProfileID($params['profile_id']);
165 if (!CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_active')) {
166 //@todo declare pseudoconstant & let api do this
167 throw new API_Exception('Invalid value for profile_id');
170 $isContactActivityProfile = CRM_Core_BAO_UFField
::checkContactActivityProfileType($profileID);
172 if (!empty($params['id']) && CRM_Core_BAO_UFField
::checkProfileType($profileID) && !$isContactActivityProfile) {
173 throw new API_Exception('Update profiles including more than one entity not currently supported');
176 $contactParams = $activityParams = $missingParams = [];
178 $profileFields = civicrm_api3('Profile', 'getfields', ['action' => 'submit', 'profile_id' => $profileID]);
179 $profileFields = $profileFields['values'];
180 if ($isContactActivityProfile) {
181 civicrm_api3_verify_mandatory($params, NULL, ['activity_id']);
183 $errors = CRM_Profile_Form
::validateContactActivityProfile($params['activity_id'],
184 $params['contact_id'],
187 if (!empty($errors)) {
188 throw new API_Exception(array_pop($errors));
192 // Add custom greeting fields
193 $greetingFields = ['email_greeting', 'postal_greeting', 'addressee'];
194 foreach ($greetingFields as $greetingField) {
195 if (isset($profileFields[$greetingField]) && !isset($profileFields["{$greetingField}_custom"])) {
196 $profileFields["{$greetingField}_custom"] = ['name' => "{$greetingField}_custom"];
200 foreach ($profileFields as $fieldName => $field) {
201 if (!isset($params[$fieldName])) {
205 $value = $params[$fieldName];
206 if ($params[$fieldName] && isset($params[$fieldName . '_id'])) {
207 $value = $params[$fieldName . '_id'];
209 $contactEntities = ['contact', 'individual', 'organization', 'household'];
210 $locationEntities = ['email', 'address', 'phone', 'website', 'im'];
212 $entity = strtolower(CRM_Utils_Array
::value('entity', $field));
213 if ($entity && !in_array($entity, array_merge($contactEntities, $locationEntities))) {
217 $contactParams['api.Note.create'] = [
219 'contact_id' => 'user_contact_id',
225 if (!is_array($value)) {
226 $value = $value ?
explode(',', $value) : [];
228 $contactParams['api.entity_tag.replace'] = [
234 $contactParams['api.' . $entity . '.create'][$fieldName] = $value;
235 //@todo we are not currently declaring this option
236 if (isset($params['batch_id']) && strtolower($entity) == 'contribution') {
237 $contactParams['api.' . $entity . '.create']['batch_id'] = $params['batch_id'];
239 if (isset($params[$entity . '_id'])) {
240 //todo possibly declare $entity_id in getfields ?
241 $contactParams['api.' . $entity . '.create']['id'] = $params[$entity . '_id'];
246 $contactParams[_civicrm_api3_profile_translate_fieldnames_for_bao($fieldName)] = $value;
249 if (isset($contactParams['api.contribution.create']) && isset($contactParams['api.membership.create'])) {
250 $contactParams['api.membership_payment.create'] = [
251 'contribution_id' => '$value.api.contribution.create.id',
252 'membership_id' => '$value.api.membership.create.id',
256 if (isset($contactParams['api.contribution.create']) && isset($contactParams['api.participant.create'])) {
257 $contactParams['api.participant_payment.create'] = [
258 'contribution_id' => '$value.api.contribution.create.id',
259 'participant_id' => '$value.api.participant.create.id',
263 $contactParams['contact_id'] = empty($params['contact_id']) ? CRM_Utils_Array
::value('id', $params) : $params['contact_id'];
264 $contactParams['profile_id'] = $profileID;
265 $contactParams['skip_custom'] = 1;
267 $contactProfileParams = civicrm_api3_profile_apply($contactParams);
269 // Contact profile fields
270 $profileParams = $contactProfileParams['values'];
272 // If profile having activity fields
273 if ($isContactActivityProfile && !empty($activityParams)) {
274 $activityParams['id'] = $params['activity_id'];
275 $profileParams['api.activity.create'] = $activityParams;
278 return civicrm_api3('contact', 'create', $profileParams);
282 * Translate field names for BAO.
284 * The api standards expect field names to be lower case but the BAO uses mixed case
285 * so we accept 'email-primary' but pass 'email-Primary' to the BAO
286 * we could make the BAO handle email-primary but this would alter the fieldname seen by hooks
287 * & we would need to consider that change
289 * @param string $fieldName
295 function _civicrm_api3_profile_translate_fieldnames_for_bao($fieldName) {
296 $fieldName = str_replace('url', 'URL', $fieldName);
297 return str_replace('primary', 'Primary', $fieldName);
301 * Metadata for submit action.
303 * @param array $params
304 * @param array $apirequest
306 function _civicrm_api3_profile_submit_spec(&$params, $apirequest) {
307 if (isset($apirequest['params']['profile_id'])) {
308 // we will return what is required for this profile
309 // note the problem with simply over-riding getfields & then calling generic if needbe is we don't have the
310 // api request array to pass to it.
311 //@todo - it may make more sense just to pass the apiRequest to getfields
312 //@todo get_options should take an array - @ the moment it is only takes 'all' - which is supported
313 // by other getfields fn
314 // we don't resolve state, country & county for performance reasons
315 $resolveOptions = CRM_Utils_Array
::value('get_options', $apirequest['params']) == 'all' ?
TRUE : FALSE;
316 $profileID = _civicrm_api3_profile_getProfileID($apirequest['params']['profile_id']);
317 $params = _civicrm_api3_buildprofile_submitfields($profileID, $resolveOptions, CRM_Utils_Array
::value('cache_clear', $params));
319 elseif (isset($apirequest['params']['cache_clear'])) {
320 _civicrm_api3_buildprofile_submitfields(FALSE, FALSE, TRUE);
322 $params['profile_id']['api.required'] = TRUE;
323 $params['profile_id']['title'] = 'Profile ID';
324 // Profile forms submit tag values as a string; hack to get past api wrapper validation
325 if (!empty($params['tag_id'])) {
326 unset($params['tag_id']['pseudoconstant']);
327 $params['tag_id']['type'] = CRM_Utils_Type
::T_STRING
;
332 * Update Profile field values.
334 * @deprecated - calling this function directly is deprecated as 'set' is not a clear action
337 * @param array $params
338 * Array of property name/value.
339 * pairs to update profile field values
342 * Updated Contact/ Activity object|CRM_Error
344 function civicrm_api3_profile_set($params) {
345 return civicrm_api3('profile', 'submit', $params);
351 * @deprecated - appears to be an internal function - should not be accessible via api
352 * Provide formatted values for profile fields.
354 * @param array $params
355 * Array of property name/value.
356 * pairs to profile field values
358 * @throws API_Exception
362 * @todo add test cases
364 function civicrm_api3_profile_apply($params) {
365 $profileFields = CRM_Core_BAO_UFGroup
::getFields($params['profile_id'],
374 CRM_Core_Permission
::EDIT
377 list($data, $contactDetails) = CRM_Contact_BAO_Contact
::formatProfileContactParams($params,
379 CRM_Utils_Array
::value('contact_id', $params),
380 $params['profile_id'],
381 CRM_Utils_Array
::value('contact_type', $params),
382 CRM_Utils_Array
::value('skip_custom', $params, FALSE)
386 throw new API_Exception('Unable to format profile parameters.');
389 return civicrm_api3_create_success($data);
393 * Adjust Metadata for Apply action.
395 * The metadata is used for setting defaults, documentation & validation.
397 * @param array $params
398 * Array of parameters determined by getfields.
400 function _civicrm_api3_profile_apply_spec(&$params) {
401 $params['profile_id']['api.required'] = 1;
402 $params['profile_id']['title'] = 'Profile ID';
406 * Get pseudo profile 'billing'.
408 * This is a function to help us 'pretend' billing is a profile & treat it like it is one.
409 * It gets standard credit card address fields etc
410 * Note this is 'better' that the inbuilt version as it will pull in fallback values
411 * billing location -> is_billing -> primary
413 * Note that that since the existing code for deriving a blank profile is not easily accessible our
414 * interim solution is just to return an empty array
416 * @param array $params
420 function _civicrm_api3_profile_getbillingpseudoprofile(&$params) {
422 $locationTypeID = CRM_Core_BAO_LocationType
::getBilling();
424 if (empty($params['contact_id'])) {
425 $config = CRM_Core_Config
::singleton();
427 'billing_first_name' => '',
428 'billing_middle_name' => '',
429 'billing_last_name' => '',
430 'email-' . $locationTypeID => '',
431 'billing_email-' . $locationTypeID => '',
432 'billing_city-' . $locationTypeID => '',
433 'billing_postal_code-' . $locationTypeID => '',
434 'billing_street_address-' . $locationTypeID => '',
435 'billing_country_id-' . $locationTypeID => $config->defaultContactCountry
,
436 'billing_state_province_id-' . $locationTypeID => $config->defaultContactStateProvince
,
441 $addressFields = ['street_address', 'city', 'state_province_id', 'country_id', 'postal_code'];
442 $result = civicrm_api3('contact', 'getsingle', [
443 'id' => $params['contact_id'],
444 'api.address.get.1' => ['location_type_id' => 'Billing', 'return' => $addressFields],
445 // getting the is_billing required or not is an extra db call but probably cheap enough as this isn't an import api
446 'api.address.get.2' => ['is_billing' => TRUE, 'return' => $addressFields],
447 'api.email.get.1' => ['location_type_id' => 'Billing'],
448 'api.email.get.2' => ['is_billing' => TRUE],
449 'return' => 'api.email.get, api.address.get, api.address.getoptions, country, state_province, email, first_name, last_name, middle_name, ' . implode($addressFields, ','),
454 'billing_first_name' => $result['first_name'],
455 'billing_middle_name' => $result['middle_name'],
456 'billing_last_name' => $result['last_name'],
459 if (!empty($result['api.address.get.1']['count'])) {
460 foreach ($addressFields as $fieldname) {
461 $values['billing_' . $fieldname . '-' . $locationTypeID] = isset($result['api.address.get.1']['values'][0][$fieldname]) ?
$result['api.address.get.1']['values'][0][$fieldname] : '';
464 elseif (!empty($result['api.address.get.2']['count'])) {
465 foreach ($addressFields as $fieldname) {
466 $values['billing_' . $fieldname . '-' . $locationTypeID] = isset($result['api.address.get.2']['values'][0][$fieldname]) ?
$result['api.address.get.2']['values'][0][$fieldname] : '';
470 foreach ($addressFields as $fieldname) {
471 $values['billing_' . $fieldname . '-' . $locationTypeID] = isset($result[$fieldname]) ?
$result[$fieldname] : '';
475 if (!empty($result['api.email.get.1']['count'])) {
476 $values['billing-email' . '-' . $locationTypeID] = $result['api.email.get.1']['values'][0]['email'];
478 elseif (!empty($result['api.email.get.2']['count'])) {
479 $values['billing-email' . '-' . $locationTypeID] = $result['api.email.get.2']['values'][0]['email'];
482 $values['billing-email' . '-' . $locationTypeID] = $result['email'];
484 // return both variants of email to reflect inconsistencies in form layer
485 $values['email' . '-' . $locationTypeID] = $values['billing-email' . '-' . $locationTypeID];
490 * Here we will build up getfields type data for all the fields in the profile.
492 * Because the integration with the form layer in core is so hard-coded we are not going to attempt to re-use it
493 * However, as this function is unit-tested & hence 'locked in' we can aspire to extract sharable
494 * code out of the form-layer over time.
496 * The function deciphers which fields belongs to which entites & retrieves metadata about the entities
497 * Unfortunately we have inconsistencies such as 'contribution' uses contribution_status_id
498 * & participant has 'participant_status' so we have to standardise from the outside in here -
499 * find the oddities, 'mask them' at this layer, add tests & work to standardise over time so we can remove this handling
501 * @param int $profileID
502 * @param int $optionsBehaviour
503 * 0 = don't resolve, 1 = resolve non-aggressively, 2 = resolve aggressively - ie include country & state.
508 function _civicrm_api3_buildprofile_submitfields($profileID, $optionsBehaviour = 1, $is_flush) {
509 static $profileFields = [];
512 if (empty($profileID)) {
516 if (isset($profileFields[$profileID])) {
517 return $profileFields[$profileID];
519 $fields = civicrm_api3('uf_field', 'get', ['uf_group_id' => $profileID]);
521 foreach ($fields['values'] as $field) {
522 if (!$field['is_active']) {
525 list($entity, $fieldName) = _civicrm_api3_map_profile_fields_to_entity($field);
527 if (strtolower($fieldName) != $fieldName) {
528 $aliasArray['api.aliases'] = [$fieldName];
529 $fieldName = strtolower($fieldName);
531 $profileFields[$profileID][$fieldName] = array_merge([
532 'api.required' => $field['is_required'],
533 'title' => $field['label'],
534 'help_pre' => CRM_Utils_Array
::value('help_pre', $field),
535 'help_post' => CRM_Utils_Array
::value('help_post', $field),
537 'weight' => CRM_Utils_Array
::value('weight', $field),
540 $ufFieldTaleFieldName = $field['field_name'];
541 if (isset($entity[$ufFieldTaleFieldName]['name'])) {
542 // in the case where we are dealing with an alias we map back to a name
543 // this will be tested by 'membership_type_id' field
544 $ufFieldTaleFieldName = $entity[$ufFieldTaleFieldName]['name'];
547 // as we build up a list of these we should be able to determine a generic approach
549 $hardCodedEntityFields = [
550 'state_province' => 'state_province_id',
551 'country' => 'country_id',
552 'participant_status' => 'status_id',
553 'gender' => 'gender_id',
554 'financial_type' => 'financial_type_id',
555 'soft_credit' => 'soft_credit_to',
556 'group' => 'group_id',
558 'soft_credit_type' => 'soft_credit_type_id',
561 if (array_key_exists($ufFieldTaleFieldName, $hardCodedEntityFields)) {
562 $ufFieldTaleFieldName = $hardCodedEntityFields[$ufFieldTaleFieldName];
565 $entities[$entity][$fieldName] = $ufFieldTaleFieldName;
568 foreach ($entities as $entity => $entityFields) {
569 $result = civicrm_api3($entity, 'getfields', ['action' => 'create']);
570 $entityGetFieldsResult = _civicrm_api3_profile_appendaliases($result['values'], $entity);
571 foreach ($entityFields as $entityfield => $realName) {
572 $fieldName = strtolower($entityfield);
573 if (!strstr($fieldName, '-')) {
574 if (strtolower($realName) != $fieldName) {
575 // we want to keep the '-' pattern for locations but otherwise
576 // we are going to make the api-standard field the main / preferred name but support the db name
577 // in future naming the fields in the DB to reflect the way the rest of the api / BAO / metadata works would
579 $fieldName = strtolower($realName);
581 if (isset($entityGetFieldsResult[$realName]['uniqueName'])) {
582 // we won't alias the field name on here are we are using uniqueNames for the possibility of needing to differentiate
583 // which entity 'status_id' belongs to
584 $fieldName = $entityGetFieldsResult[$realName]['uniqueName'];
587 if (isset($entityGetFieldsResult[$realName]['name'])) {
588 // this will sort out membership_type_id vs membership_type
589 $fieldName = $entityGetFieldsResult[$realName]['name'];
593 $profileFields[$profileID][$fieldName] = array_merge($entityGetFieldsResult[$realName], $profileFields[$profileID][$entityfield]);
594 if (!isset($profileFields[$profileID][$fieldName]['api.aliases'])) {
595 $profileFields[$profileID][$fieldName]['api.aliases'] = [];
597 if ($optionsBehaviour && !empty($entityGetFieldsResult[$realName]['pseudoconstant'])) {
598 if ($optionsBehaviour > 1 ||
!in_array($realName, ['state_province_id', 'county_id', 'country_id'])) {
599 $options = civicrm_api3($entity, 'getoptions', ['field' => $realName]);
600 $profileFields[$profileID][$fieldName]['options'] = $options['values'];
604 if ($entityfield != $fieldName) {
605 if (isset($profileFields[$profileID][$entityfield])) {
606 unset($profileFields[$profileID][$entityfield]);
608 if (!in_array($entityfield, $profileFields[$profileID][$fieldName]['api.aliases'])) {
609 // we will make the mixed case version (e.g. of 'Primary') an alias
610 $profileFields[$profileID][$fieldName]['api.aliases'][] = $entityfield;
614 * putting this on hold -this would cause the api to set the default - but could have unexpected behaviour
615 * if (isset($result['values'][$realName]['default_value'])) {
616 * //this would be the case for a custom field with a configured default
617 * $profileFields[$profileID][$entityfield]['api.default'] = $result['values'][$realName]['default_value'];
622 uasort($profileFields[$profileID], "_civicrm_api3_order_by_weight");
623 return $profileFields[$profileID];
632 function _civicrm_api3_order_by_weight($a, $b) {
633 return CRM_Utils_Array
::value('weight', $b) < CRM_Utils_Array
::value('weight', $a) ?
TRUE : FALSE;
637 * Here we map the profile fields as stored in the uf_field table to their 'real entity'
638 * we also return the profile fieldname
644 function _civicrm_api3_map_profile_fields_to_entity(&$field) {
645 $entity = $field['field_type'];
646 $contactTypes = civicrm_api3('contact', 'getoptions', ['field' => 'contact_type']);
647 if (in_array($entity, $contactTypes['values'])) {
650 $entity = _civicrm_api_get_entity_name_from_camel($entity);
651 $locationFields = ['email' => 'email'];
652 $fieldName = $field['field_name'];
653 if (!empty($field['location_type_id'])) {
654 if ($fieldName == 'email') {
660 $fieldName .= '-' . $field['location_type_id'];
662 elseif (array_key_exists($fieldName, $locationFields)) {
663 $fieldName .= '-Primary';
666 if (!empty($field['phone_type_id'])) {
667 $fieldName .= '-' . $field['location_type_id'];
671 // @todo - sort this out!
672 //here we do a hard-code list of known fields that don't map to where they are mapped to
673 // not a great solution but probably if we looked in the BAO we'd find a scary switch statement
674 // in a perfect world the uf_field table would hold the correct entity for each item
675 // & only the relationships between entities would need to be coded
676 $hardCodedEntityMappings = [
677 'street_address' => 'address',
678 'street_number' => 'address',
679 'supplemental_address_1' => 'address',
680 'supplemental_address_2' => 'address',
681 'supplemental_address_3' => 'address',
682 'postal_code' => 'address',
685 'state_province' => 'address',
686 'country' => 'address',
687 'county' => 'address',
688 //note that in discussions about how to restructure the api we discussed making these membership
689 // fields into 'membership_payment' fields - which would entail declaring them in getfields
690 // & renaming them in existing profiles
691 'financial_type' => 'contribution',
692 'total_amount' => 'contribution',
693 'receive_date' => 'contribution',
694 'payment_instrument' => 'contribution',
695 'contribution_check_number' => 'contribution',
696 'contribution_status_id' => 'contribution',
697 'soft_credit' => 'contribution',
698 'soft_credit_type' => 'contribution_soft',
699 'group' => 'group_contact',
700 'tag' => 'entity_tag',
703 if (array_key_exists($fieldName, $hardCodedEntityMappings)) {
704 $entity = $hardCodedEntityMappings[$fieldName];
706 return [$entity, $fieldName];
710 * @todo this should be handled by the api wrapper using getfields info - need to check
711 * how we add a a pseudoconstant to this pseudo api to make that work
713 * @param int $profileID
716 * @throws CiviCRM_API3_Exception
718 function _civicrm_api3_profile_getProfileID($profileID) {
719 if (!empty($profileID) && strtolower($profileID) != 'billing' && !is_numeric($profileID)) {
720 $profileID = civicrm_api3('uf_group', 'getvalue', ['return' => 'id', 'name' => $profileID]);
726 * helper function to add all aliases as keys to getfields response so we can look for keys within it
727 * since the relationship between profile fields & api / metadata based fields is a bit inconsistent
729 * @param array $values
731 * e.g getfields response incl 'membership_type_id' - with api.aliases = 'membership_type'
732 * returned array will include both as keys (with the same values)
737 function _civicrm_api3_profile_appendaliases($values, $entity) {
738 foreach ($values as $field => $spec) {
739 if (!empty($spec['api.aliases'])) {
740 foreach ($spec['api.aliases'] as $alias) {
741 $values[$alias] = $spec;
744 if (!empty($spec['uniqueName'])) {
745 $values[$spec['uniqueName']] = $spec;
748 //special case on membership & contribution - can't see how to handle in a generic way
749 if (in_array($entity, ['membership', 'contribution'])) {
750 $values['send_receipt'] = ['title' => 'Send Receipt', 'type' => (int) 16];
756 * @deprecated api notice
758 * Array of deprecated actions
760 function _civicrm_api3_profile_deprecation() {
762 'set' => 'Profile api "set" action is deprecated in favor of "submit".',
763 'apply' => 'Profile api "apply" action is deprecated in favor of "submit".',