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 option values.
15 * Values are grouped by "OptionGroup"
17 * @package CiviCRM_APIv3
21 * Retrieve one or more option values.
23 * @param array $params
28 function civicrm_api3_option_value_get($params) {
29 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params, 'OptionValue');
33 * Adjust Metadata for get action.
35 * The metadata is used for setting defaults, documentation & validation.
37 * @param array $params
38 * Array of parameters determined by getfields.
40 function _civicrm_api3_option_value_get_spec(&$params) {
41 $params['option_group_id']['api.aliases'] = ['option_group_name'];
47 * @param array $params
49 * @throws API_Exception
53 function civicrm_api3_option_value_create($params) {
54 $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__
), $params, 'OptionValue');
55 if (!empty($params['id']) && !array_key_exists('option_group_id', $params)) {
56 $groupId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionValue',
57 $params['id'], 'option_group_id', 'id'
61 $groupId = $params['option_group_id'];
64 civicrm_api('option_value', 'getfields', ['version' => 3, 'cache_clear' => 1, 'option_group_id' => $groupId]);
69 * Adjust Metadata for Create action.
71 * The metadata is used for setting defaults, documentation & validation.
73 * @param array $params
74 * Array of parameters determined by getfields.
76 function _civicrm_api3_option_value_create_spec(&$params) {
77 $params['is_active']['api.default'] = 1;
78 //continue to support component
79 $params['component_id']['api.aliases'] = ['component'];
80 // $params['name']['api.aliases'] = array('label');
81 $params['option_group_id']['api.required'] = TRUE;
85 * Deletes an existing option value.
87 * @param array $params
88 * @return array API result array
89 * @throws API_Exception
91 function civicrm_api3_option_value_delete($params) {
92 // We will get the option group id before deleting so we can flush pseudoconstants.
93 $optionGroupID = civicrm_api('option_value', 'getvalue', ['version' => 3, 'id' => $params['id'], 'return' => 'option_group_id']);
94 $result = CRM_Core_BAO_OptionValue
::del($params['id']);
96 civicrm_api('option_value', 'getfields', ['version' => 3, 'cache_clear' => 1, 'option_group_id' => $optionGroupID]);
97 return civicrm_api3_create_success();
100 throw new API_Exception('Could not delete OptionValue ' . $params['id']);