X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;ds=sidebyside;f=api%2Fv3%2FCustomField.php;h=2cea880732ab606f03fbd7a5d59564cd27d6a33c;hb=f36c9ebc31dd6049ad9e6821b6f0b18bb3c4820d;hp=bfcf45e4cd34ec6c4f02a6fdd999bcb71ac14fea;hpb=df0d084d2f97bf12a241e1e23809802e4ac8f5ed;p=civicrm-core.git diff --git a/api/v3/CustomField.php b/api/v3/CustomField.php index bfcf45e4cd..2cea880732 100644 --- a/api/v3/CustomField.php +++ b/api/v3/CustomField.php @@ -1,9 +1,9 @@ $value) { + // Translate simple key/value pairs into full-blown option values + if (!is_array($value)) { + $value = array( + 'label' => $value, + 'value' => $key, + 'is_active' => 1, + 'weight' => $weight, + ); + $key = $weight++; + } $params['option_label'][$key] = $value['label']; $params['option_value'][$key] = $value['value']; $params['option_status'][$key] = $value['is_active']; @@ -63,14 +70,14 @@ function civicrm_api3_custom_field_create($params) { $customField = CRM_Core_BAO_CustomField::create($params); _civicrm_api3_object_to_array_unique_fields($customField, $values[$customField->id]); _civicrm_api3_custom_field_flush_static_caches(); - return civicrm_api3_create_success($values, $params, 'custom_field', $customField); + return civicrm_api3_create_success($values, $params, 'CustomField', $customField); } /** * Flush static caches in functions that might have stored available custom fields. */ function _civicrm_api3_custom_field_flush_static_caches() { - civicrm_api('custom_field', 'getfields', array('version' => 3, 'cache_clear' => 1)); + civicrm_api('CustomField', 'getfields', array('version' => 3, 'cache_clear' => 1)); CRM_Core_BAO_UFField::getAvailableFieldsFlat(TRUE); } @@ -78,14 +85,20 @@ function _civicrm_api3_custom_field_flush_static_caches() { * Adjust Metadata for Create action. * * @param array $params - * Array or parameters determined by getfields. + * Array of parameters determined by getfields. */ function _civicrm_api3_custom_field_create_spec(&$params) { $params['label']['api.required'] = 1; $params['custom_group_id']['api.required'] = 1; $params['is_active']['api.default'] = 1; + $params['option_values'] = array( + 'title' => 'Option Values', + 'description' => "Pass an array of options (value => label) to create this field's option values", + ); + // TODO: Why expose this to the api at all? $params['option_type'] = array( - 'title' => 'This (boolean) field tells the BAO to create an option group for the field if the field type is appropriate', + 'title' => 'Option Type', + 'description' => 'This (boolean) field tells the BAO to create an option group for the field if the field type is appropriate', 'api.default' => 1, 'type' => CRM_Utils_Type::T_BOOLEAN, ); @@ -94,7 +107,7 @@ function _civicrm_api3_custom_field_create_spec(&$params) { } /** - * Use this API to delete an existing custom group field. + * Use this API to delete an existing custom field. * * @param array $params * Array id of the field to be deleted. @@ -106,7 +119,7 @@ function civicrm_api3_custom_field_delete($params) { $field->id = $params['id']; $field->find(TRUE); $customFieldDelete = CRM_Core_BAO_CustomField::deleteField($field); - civicrm_api('custom_field', 'getfields', array('version' => 3, 'cache_clear' => 1)); + civicrm_api('CustomField', 'getfields', array('version' => 3, 'cache_clear' => 1)); return $customFieldDelete ? civicrm_api3_create_error('Error while deleting custom field') : civicrm_api3_create_success(); } @@ -257,7 +270,7 @@ SELECT count(*) */ function civicrm_api3_custom_field_setvalue($params) { require_once 'api/v3/Generic/Setvalue.php'; - $result = civicrm_api3_generic_setValue(array("entity" => 'custom_field', 'params' => $params)); + $result = civicrm_api3_generic_setValue(array("entity" => 'CustomField', 'params' => $params)); if (empty($result['is_error'])) { CRM_Utils_System::flushCache(); }