'name' => [
'title' => 'name of setting field',
'api.required' => 1,
- 'type' => CRM_Utils_Type::T_STRING],
+ 'type' => CRM_Utils_Type::T_STRING,
+ ],
'group' => [
'api.required' => 0,
'title' => 'Setting Group',
'description' => 'Settings Group. This is required if the setting is not stored in config',
- 'type' => CRM_Utils_Type::T_STRING],
+ 'type' => CRM_Utils_Type::T_STRING,
+ ],
];
return civicrm_api3_create_success($result, $params, 'Setting', 'getfields');
}
}
return civicrm_api3_create_success($defaults, $params, 'Setting', 'getfields');
}
+
/**
* Metadata for Setting create function.
*
* @throws \API_Exception
*/
function civicrm_api3_setting_getoptions($params) {
- $specs = CRM_Core_BAO_Setting::getSettingSpecification();
+ $domainId = CRM_Utils_Array::value('domain_id', $params);
+ $specs = \Civi\Core\SettingsMetadata::getMetadata(['name' => $params['field']], $domainId, TRUE);
- if (empty($specs[$params['field']]) || empty($specs[$params['field']]['pseudoconstant'])) {
+ if (empty($specs[$params['field']]) || !is_array(CRM_Utils_Array::value('options', $specs[$params['field']]))) {
throw new API_Exception("The field '" . $params['field'] . "' has no associated option list.");
}
- $pseudoconstant = $specs[$params['field']]['pseudoconstant'];
-
- // It would be nice if we could leverage CRM_Core_PseudoConstant::get() somehow,
- // but it's tightly coupled to DAO/field. However, if you really need to support
- // more pseudoconstant types, then probably best to refactor it. For now, KISS.
- if (!empty($pseudoconstant['callback'])) {
- $values = Civi\Core\Resolver::singleton()->call($pseudoconstant['callback'], []);
- return civicrm_api3_create_success($values, $params, 'Setting', 'getoptions');
- }
- elseif (!empty($pseudoconstant['optionGroupName'])) {
- $keyColumn = 'value';
- if (!empty($pseudoconstant['keyColumn'])) {
- $keyColumn = $pseudoconstant['keyColumn'];
- }
- return civicrm_api3_create_success(
- CRM_Core_OptionGroup::values($pseudoconstant['optionGroupName'], FALSE, FALSE, TRUE, NULL, 'label', TRUE, FALSE, $keyColumn),
- $params, 'Setting', 'getoptions'
- );
- }
-
- throw new API_Exception("The field '" . $params['field'] . "' uses an unsupported option list.");
+ return civicrm_api3_create_success($specs[$params['field']]['options'], $params, 'Setting', 'getoptions');
}
/**
$result = CRM_Core_BAO_Setting::getItems($params, $domains, CRM_Utils_Array::value('return', $params, []));
return civicrm_api3_create_success($result, $params, 'Setting', 'get');
}
+
/**
* Metadata for setting create function.
*
'description' => 'if you know the group defining it will make the api more efficient',
];
}
+
/**
* Returns value for specific parameter.
*
}
if ($params['domain_id'] == 'current_domain') {
- $params['domain_id'] = CRM_Core_Config::domainID();
+ $params['domain_id'] = CRM_Core_Config::domainID();
}
if ($params['domain_id'] == 'all') {