3 abstract class PhabricatorSelectSetting
4 extends PhabricatorSetting
{
6 abstract protected function getSelectOptions();
8 final protected function newCustomEditField($object) {
9 $setting_key = $this->getSettingKey();
10 $default_value = $object->getDefaultValue($setting_key);
12 $options = $this->getSelectOptions();
14 if (isset($options[$default_value])) {
15 $default_label = pht('Default (%s)', $options[$default_value]);
17 $default_label = pht('Default (Unknown, "%s")', $default_value);
20 if (empty($options[''])) {
26 return $this->newEditField($object, new PhabricatorSelectEditField())
27 ->setOptions($options);
30 public function assertValidValue($value) {
31 // This is a slightly stricter check than the transaction check. It's
32 // OK for empty string to go through transactions because it gets converted
33 // to null later, but we shouldn't be reading the empty string from
35 if ($value === null) {
39 if (!strlen($value)) {
42 'Empty string is not a valid setting for "%s".',
43 $this->getSettingName()));
46 $this->validateTransactionValue($value);
49 final public function validateTransactionValue($value) {
50 $value = phutil_string_cast($value);
51 if (!strlen($value)) {
55 $options = $this->getSelectOptions();
57 if (!isset($options[$value])) {
60 'Value "%s" is not valid for setting "%s": valid values are %s.',
62 $this->getSettingName(),
63 implode(', ', array_keys($options))));
69 public function getTransactionNewValue($value) {
70 $value = phutil_string_cast($value);
72 if (!strlen($value)) {