Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / settings / setting / PhabricatorOptionGroupSetting.php
blob645b6bc2e1eddce5833c3731ae5f30016aee16bc
1 <?php
3 abstract class PhabricatorOptionGroupSetting
4 extends PhabricatorSetting {
6 abstract protected function getSelectOptionGroups();
8 final protected function getSelectOptionMap() {
9 $groups = $this->getSelectOptionGroups();
11 $map = array();
12 foreach ($groups as $group) {
13 $map += $group['options'];
16 return $map;
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]);
28 } else {
29 $default_label = pht('Default (Unknown, "%s")', $default_value);
32 $head_key = head_key($options);
33 $options[$head_key]['options'] = array(
34 '' => $default_label,
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)) {
48 return;
51 $map = $this->getSelectOptionMap();
53 if (!isset($map[$value])) {
54 throw new Exception(
55 pht(
56 'Value "%s" is not valid for setting "%s": valid values are %s.',
57 $value,
58 $this->getSettingName(),
59 implode(', ', array_keys($map))));
62 return;
65 public function getTransactionNewValue($value) {
66 if (!strlen($value)) {
67 return null;
70 return (string)$value;