3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * This api exposes CiviCRM profile field.
15 * @package CiviCRM_APIv3
19 * Defines 'uf field' within a group.
21 * @param array $params
22 * Array per getfields metadata.
24 * @throws API_Exception
27 * Newly created $ufFieldArray
29 function civicrm_api3_uf_field_create($params) {
30 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__
), $params, 'UFField');
34 * Adjust metadata for civicrm_uf_field create.
36 * @param array $params
38 function _civicrm_api3_uf_field_create_spec(&$params) {
39 $params['field_name']['api.required'] = TRUE;
40 $params['uf_group_id']['api.required'] = TRUE;
42 $params['option.autoweight'] = [
43 'title' => "Auto Weight",
44 'description' => "Automatically adjust weights in UFGroup to align with UFField",
45 'type' => CRM_Utils_Type
::T_BOOLEAN
,
46 'api.default' => TRUE,
48 $params['is_active']['api.default'] = TRUE;
52 * Returns array of uf groups (profiles) matching a set of one or more group properties.
54 * @param array $params
55 * Array per getfields metadata.
59 function civicrm_api3_uf_field_get($params) {
60 return _civicrm_api3_basic_get('CRM_Core_BAO_UFField', $params);
66 * @param array $params
68 * @throws API_Exception
72 function civicrm_api3_uf_field_delete($params) {
73 $fieldId = $params['id'];
75 $ufGroupId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFField', $fieldId, 'uf_group_id');
77 throw new API_Exception('Invalid value for field_id.');
80 $result = CRM_Core_BAO_UFField
::del($fieldId);
82 $fieldsType = CRM_Core_BAO_UFGroup
::calculateGroupType($ufGroupId, TRUE);
83 CRM_Core_BAO_UFGroup
::updateGroupTypes($ufGroupId, $fieldsType);
85 return civicrm_api3_create_success($result, $params);
89 * Field id accepted for backward compatibility - unset required on id.
91 * @param array $params
93 function _civicrm_api3_uf_field_delete_spec(&$params) {
94 // legacy support for field_id
95 $params['id']['api.aliases'] = ['field_id'];