3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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 profile field.
31 * @package CiviCRM_APIv3
35 * Defines 'uf field' within a group.
37 * @param array $params
38 * Array per getfields metadata.
40 * @throws API_Exception
43 * Newly created $ufFieldArray
45 function civicrm_api3_uf_field_create($params) {
46 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__
), $params, 'UFField');
50 * Adjust metadata for civicrm_uf_field create.
52 * @param array $params
54 function _civicrm_api3_uf_field_create_spec(&$params) {
55 $params['field_name']['api.required'] = TRUE;
56 $params['uf_group_id']['api.required'] = TRUE;
58 $params['option.autoweight'] = array(
59 'title' => "Auto Weight",
60 'description' => "Automatically adjust weights in UFGroup to align with UFField",
61 'type' => CRM_Utils_Type
::T_BOOLEAN
,
62 'api.default' => TRUE,
64 $params['is_active']['api.default'] = TRUE;
68 * Returns array of uf groups (profiles) matching a set of one or more group properties.
70 * @param array $params
71 * Array per getfields metadata.
75 function civicrm_api3_uf_field_get($params) {
76 return _civicrm_api3_basic_get('CRM_Core_BAO_UFField', $params);
82 * @param array $params
84 * @throws API_Exception
88 function civicrm_api3_uf_field_delete($params) {
89 $fieldId = $params['id'];
91 $ufGroupId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFField', $fieldId, 'uf_group_id');
93 throw new API_Exception('Invalid value for field_id.');
96 $result = CRM_Core_BAO_UFField
::del($fieldId);
98 $fieldsType = CRM_Core_BAO_UFGroup
::calculateGroupType($ufGroupId, TRUE);
99 CRM_Core_BAO_UFGroup
::updateGroupTypes($ufGroupId, $fieldsType);
101 return civicrm_api3_create_success($result, $params);
105 * Field id accepted for backward compatibility - unset required on id.
107 * @param array $params
109 function _civicrm_api3_uf_field_delete_spec(&$params) {
110 // legacy support for field_id
111 $params['id']['api.aliases'] = array('field_id');