Merge pull request #17656 from civicrm/5.27
[civicrm-core.git] / api / v3 / OptionGroup.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * This api exposes CiviCRM option groups.
14 *
15 * OptionGroups are containers for option values.
16 *
17 * @package CiviCRM_APIv3
18 */
19
20 /**
21 * Get option groups.
22 *
23 * @param array $params
24 *
25 * @return array
26 */
27 function civicrm_api3_option_group_get($params) {
28 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
29 }
30
31 /**
32 * Create/update option group.
33 *
34 * @param array $params
35 * Array per getfields metadata.
36 *
37 * @return array
38 */
39 function civicrm_api3_option_group_create($params) {
40 $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'OptionGroup');
41 civicrm_api('option_value', 'getfields', ['version' => 3, 'cache_clear' => 1]);
42 return $result;
43 }
44
45 /**
46 * Adjust Metadata for Create action.
47 *
48 * The metadata is used for setting defaults, documentation & validation.
49 *
50 * @param array $params
51 * Array of parameters determined by getfields.
52 */
53 function _civicrm_api3_option_group_create_spec(&$params) {
54 $params['name']['api.unique'] = 1;
55 $params['is_active']['api.default'] = TRUE;
56 }
57
58 /**
59 * Delete an existing Option Group.
60 *
61 * This method is used to delete any existing OptionGroup given its id.
62 *
63 * @param array $params
64 * [id]
65 *
66 * @return array
67 * API Result Array
68 */
69 function civicrm_api3_option_group_delete($params) {
70 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
71 }