Skip to content
Snippets Groups Projects
Commit 3f1a97cd authored by eileen's avatar eileen
Browse files

updated example & a couple of tidy ups to throw API_Exception rather than legacy

parent 3e93ae67
No related branches found
No related tags found
No related merge requests found
...@@ -54,7 +54,7 @@ function civicrm_api3_uf_field_create($params) { ...@@ -54,7 +54,7 @@ function civicrm_api3_uf_field_create($params) {
civicrm_api3_verify_one_mandatory($params, NULL, array('field_name', 'uf_group_id')); civicrm_api3_verify_one_mandatory($params, NULL, array('field_name', 'uf_group_id'));
$groupId = CRM_Utils_Array::value('uf_group_id', $params); $groupId = CRM_Utils_Array::value('uf_group_id', $params);
if ((int) $groupId < 1) { if ((int) $groupId < 1) {
return civicrm_api3_create_error('Params must be a field_name-carrying array and a positive integer.'); throw new API_Exception('Params must be a field_name-carrying array and a positive integer.');
} }
$field_type = CRM_Utils_Array::value('field_type', $params); $field_type = CRM_Utils_Array::value('field_type', $params);
...@@ -63,7 +63,7 @@ function civicrm_api3_uf_field_create($params) { ...@@ -63,7 +63,7 @@ function civicrm_api3_uf_field_create($params) {
$phone_type = CRM_Utils_Array::value('phone_type_id', $params, CRM_Utils_Array::value('phone_type', $params)); $phone_type = CRM_Utils_Array::value('phone_type_id', $params, CRM_Utils_Array::value('phone_type', $params));
if (! CRM_Core_BAO_UFField::isValidFieldName($field_name)) { if (! CRM_Core_BAO_UFField::isValidFieldName($field_name)) {
return civicrm_api3_create_error('The field_name is not valid'); throw new API_Exception('The field_name is not valid');
} }
$params['field_name'] = array($field_type, $field_name, $location_type_id, $phone_type); $params['field_name'] = array($field_type, $field_name, $location_type_id, $phone_type);
...@@ -86,13 +86,13 @@ function civicrm_api3_uf_field_create($params) { ...@@ -86,13 +86,13 @@ function civicrm_api3_uf_field_create($params) {
} }
} }
else { 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; $ids['uf_field'] = $fieldId;
} }
if (CRM_Core_BAO_UFField::duplicateField($params, $ids)) { 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.");
} }
if (CRM_Utils_Array::value('option.autoweight', $params, TRUE)) { if (CRM_Utils_Array::value('option.autoweight', $params, TRUE)) {
$params['weight'] = CRM_Core_BAO_UFField::autoWeight($params); $params['weight'] = CRM_Core_BAO_UFField::autoWeight($params);
...@@ -150,7 +150,7 @@ function civicrm_api3_uf_field_delete($params) { ...@@ -150,7 +150,7 @@ function civicrm_api3_uf_field_delete($params) {
$ufGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFField', $fieldId, 'uf_group_id'); $ufGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFField', $fieldId, 'uf_group_id');
if (!$ufGroupId) { 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); $result = CRM_Core_BAO_UFField::del($fieldId);
......
...@@ -574,6 +574,7 @@ function contact_getfields_expectedresult(){ ...@@ -574,6 +574,7 @@ function contact_getfields_expectedresult(){
'date_format' => '', 'date_format' => '',
'time_format' => '', 'time_format' => '',
'name' => 'custom_1', 'name' => 'custom_1',
'type' => 2,
'options' => array( 'options' => array(
'1' => 'Label1', '1' => 'Label1',
'2' => 'Label2', '2' => 'Label2',
...@@ -582,6 +583,7 @@ function contact_getfields_expectedresult(){ ...@@ -582,6 +583,7 @@ function contact_getfields_expectedresult(){
'current_employer' => array( 'current_employer' => array(
'title' => 'Current Employer', 'title' => 'Current Employer',
'description' => 'Name of Current Employer', 'description' => 'Name of Current Employer',
'type' => 2,
), ),
'dupe_check' => array( 'dupe_check' => array(
'title' => 'Check for Duplicates', 'title' => 'Check for Duplicates',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment