3 abstract class PhabricatorOptionGroupSetting
4 extends PhabricatorSetting
{
6 abstract protected function getSelectOptionGroups();
8 final protected function getSelectOptionMap() {
9 $groups = $this->getSelectOptionGroups();
12 foreach ($groups as $group) {
13 $map +
= $group['options'];
19 final protected function newCustomEditField($object) {
20 $setting_key = $this->getSettingKey();
21 $default_value = $object->getDefaultValue($setting_key);
23 $options = $this->getSelectOptionGroups();
25 $map = $this->getSelectOptionMap();
26 if (isset($map[$default_value])) {
27 $default_label = pht('Default (%s)', $map[$default_value]);
29 $default_label = pht('Default (Unknown, "%s")', $default_value);
32 $head_key = head_key($options);
33 $options[$head_key]['options'] = array(
35 ) +
$options[$head_key]['options'];
37 $flat_options = array();
38 foreach ($options as $group) {
39 $flat_options[$group['label']] = $group['options'];
42 return $this->newEditField($object, new PhabricatorSelectEditField())
43 ->setOptions($flat_options);
46 final public function validateTransactionValue($value) {
47 if (!strlen($value)) {
51 $map = $this->getSelectOptionMap();
53 if (!isset($map[$value])) {
56 'Value "%s" is not valid for setting "%s": valid values are %s.',
58 $this->getSettingName(),
59 implode(', ', array_keys($map))));
65 public function getTransactionNewValue($value) {
66 if (!strlen($value)) {
70 return (string)$value;