/** * Get fields for setting api calls. * * @param array $params * * @return array */ function civicrm_api3_setting_getfields($params) { if (!empty($params['action']) && strtolower($params['action']) == 'getvalue') { $result = array('name' => array('title' => 'name of setting field', 'api.required' => 1, 'type' => CRM_Utils_Type::T_STRING), 'group' => array('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)); return civicrm_api3_create_success($result, $params, 'Setting', 'getfields'); } if (!empty($params['name'])) { //am of two minds about special handling for 'name' as opposed to other filters - but is does make most common //usage really easy $params['filters']['name'] = $params['name']; } $result = CRM_Core_BAO_Setting::getSettingSpecification(CRM_Utils_Array::value('component_id', $params), CRM_Utils_Array::value('filters', $params, array()), CRM_Utils_Array::value('domain_id', $params, NULL), CRM_Utils_Array::value('profile', $params, NULL)); // find any supplemental information if (!empty($params['action'])) { $specFunction = '_civicrm_api3_setting_' . strtolower($params['action']) . '_spec'; if (function_exists($specFunction)) { $specFunction($result); } } return civicrm_api3_create_success($result, $params, 'Setting', 'getfields'); }
/** * Get options for settings. * * @param array $params * * @return array * @throws \API_Exception */ function civicrm_api3_setting_getoptions($params) { $specs = CRM_Core_BAO_Setting::getSettingSpecification(); if (empty($specs[$params['field']]) || empty($specs[$params['field']]['pseudoconstant'])) { 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'], array()); return civicrm_api3_create_success($values, $params, 'Setting', 'getoptions'); } throw new API_Exception("The field '" . $params['field'] . "' uses an unsupported option list."); }