* NOTE: Rather than calling this function directly use CRM_*_BAO_*::buildOptions()
* @see http://wiki.civicrm.org/confluence/display/CRMDOC/Pseudoconstant+%28option+list%29+Reference
*
+ * NOTE: If someone undertakes a refactoring of this, please consider the use-case of
+ * the Setting.getoptions API. There is no DAO/field, but it would be nice to use the
+ * same 'pseudoconstant' struct in *.settings.php. This means loosening the coupling
+ * between $field lookup and the $pseudoconstant evaluation.
+ *
* @param string $daoName
* @param string $fieldName
* @param array $params
);
}
+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.");
+}
+
/**
* Revert settings to defaults.
*