3 abstract class PhabricatorSetting
extends Phobject
{
5 private $viewer = false;
7 public function setViewer(PhabricatorUser
$viewer = null) {
8 $this->viewer
= $viewer;
12 public function getViewer() {
13 if ($this->viewer
=== false) {
14 throw new PhutilInvalidStateException('setViewer');
19 abstract public function getSettingName();
21 public function getSettingPanelKey() {
25 protected function getSettingOrder() {
29 public function getSettingOrderVector() {
30 return id(new PhutilSortVector())
31 ->addInt($this->getSettingOrder())
32 ->addString($this->getSettingName());
35 protected function getControlInstructions() {
39 protected function isEnabledForViewer(PhabricatorUser
$viewer) {
43 public function getSettingDefaultValue() {
47 final public function getSettingKey() {
48 return $this->getPhobjectClassConstant('SETTINGKEY');
51 public static function getAllSettings() {
52 return id(new PhutilClassMapQuery())
53 ->setAncestorClass(__CLASS__
)
54 ->setUniqueMethod('getSettingKey')
58 public static function getAllEnabledSettings(PhabricatorUser
$viewer) {
59 $settings = self
::getAllSettings();
60 foreach ($settings as $key => $setting) {
61 if (!$setting->isEnabledForViewer($viewer)) {
62 unset($settings[$key]);
68 final public function newCustomEditFields($object) {
71 $field = $this->newCustomEditField($object);
79 protected function newCustomEditField($object) {
83 protected function newEditField($object, PhabricatorEditField
$template) {
84 $setting_property = PhabricatorUserPreferencesTransaction
::PROPERTY_SETTING
;
85 $setting_key = $this->getSettingKey();
86 $value = $object->getPreference($setting_key);
87 $xaction_type = PhabricatorUserPreferencesTransaction
::TYPE_SETTING
;
88 $label = $this->getSettingName();
91 ->setKey($setting_key)
94 ->setTransactionType($xaction_type)
95 ->setMetadataValue($setting_property, $setting_key);
97 $instructions = $this->getControlInstructions();
98 if (strlen($instructions)) {
99 $template->setControlInstructions($instructions);
105 public function validateTransactionValue($value) {
109 public function assertValidValue($value) {
110 $this->validateTransactionValue($value);
113 public function getTransactionNewValue($value) {
117 public function expandSettingTransaction($object, $xaction) {
118 return array($xaction);
121 protected function newSettingTransaction($object, $key, $value) {
122 $setting_property = PhabricatorUserPreferencesTransaction
::PROPERTY_SETTING
;
123 $xaction_type = PhabricatorUserPreferencesTransaction
::TYPE_SETTING
;
125 return id(clone $object->getApplicationTransactionTemplate())
126 ->setTransactionType($xaction_type)
127 ->setMetadataValue($setting_property, $key)
128 ->setNewValue($value);