X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fv3%2FUFField.php;h=72d48e4c1d3731c3913fef7e262d6028a286d4fc;hb=151da6c31b326c6819e346ee48954ae83b383920;hp=030bd99c1362c1ecd0e3289ad4133eab19b38cab;hpb=2dd714c481b97664fec971bea74716060015059c;p=civicrm-core.git diff --git a/api/v3/UFField.php b/api/v3/UFField.php index 030bd99c13..72d48e4c1d 100644 --- a/api/v3/UFField.php +++ b/api/v3/UFField.php @@ -1,9 +1,8 @@ id = $fieldId; if ($UFField->find(TRUE)) { $ids['uf_group'] = $UFField->uf_group_id; @@ -87,14 +87,15 @@ function civicrm_api3_uf_field_create($params) { } } else { - return civicrm_api3_create_error("there is no field for this fieldId"); + throw new API_Exception("there is no field for this fieldId"); } $ids['uf_field'] = $fieldId; } if (CRM_Core_BAO_UFField::duplicateField($params, $ids)) { - return civicrm_api3_create_error("The field was not added. It already exists in this profile."); + throw new API_Exception("The field was not added. It already exists in this profile."); } + //@todo why is this even optional? Surely weight should just be 'managed' ?? if (CRM_Utils_Array::value('option.autoweight', $params, TRUE)) { $params['weight'] = CRM_Core_BAO_UFField::autoWeight($params); } @@ -104,19 +105,25 @@ function civicrm_api3_uf_field_create($params) { CRM_Core_BAO_UFGroup::updateGroupTypes($groupId, $fieldsType); _civicrm_api3_object_to_array($ufField, $ufFieldArray[$ufField->id]); + civicrm_api3('profile', 'getfields', array('cache_clear' => TRUE)); return civicrm_api3_create_success($ufFieldArray, $params); } /** * Gets field for civicrm_uf_field create * + * @param $params + * * @return array fields valid for other functions */ function _civicrm_api3_uf_field_create_spec(&$params) { $params['option.autoweight'] = array( 'title' => "Automatically adjust weights in UFGroup to align with UFField", - 'type' => CRM_Utils_Type::T_BOOL + 'type' => CRM_Utils_Type::T_BOOLEAN, + 'api.default' => TRUE, ); + $params['created_id']['api.default'] = 'user_contact_id'; + $params['is_active']['api.default'] = TRUE; } /** @@ -138,7 +145,10 @@ function civicrm_api3_uf_field_get($params) { /** * Delete uf field * - * @param $fieldId int Valid uf_field id that to be deleted + * @param $params + * + * @throws API_Exception + * @internal param int $fieldId Valid uf_field id that to be deleted * * @return true on successful delete or return error * @@ -151,7 +161,7 @@ function civicrm_api3_uf_field_delete($params) { $ufGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFField', $fieldId, 'uf_group_id'); if (!$ufGroupId) { - return civicrm_api3_create_error('Invalid value for field_id.'); + throw new API_Exception('Invalid value for field_id.'); } $result = CRM_Core_BAO_UFField::del($fieldId); @@ -161,8 +171,8 @@ function civicrm_api3_uf_field_delete($params) { return civicrm_api3_create_success($result, $params); } -/* - * field id accepted for backward compat - unset required on id +/** + * field id accepted for backward compatibility - unset required on id */ function _civicrm_api3_uf_field_delete_spec(&$params) { // legacy support for field_id