Summary: Ref T4103. This starts breaking out settings in a modern way to prepare for global defaults. Test Plan: - Edited diff settings. - Saw them take effect in primary settings pane. - Set stuff to new automatic defaults. - Tried to edit another user's settings. - Edited a bot's settings as an administrator. {F1669077} Reviewers: chad Reviewed By: chad Maniphest Tasks: T4103 Differential Revision: https://secure.phabricator.com/D15995
97 lines
2.2 KiB
PHP
97 lines
2.2 KiB
PHP
<?php
|
|
|
|
abstract class PhabricatorSetting extends Phobject {
|
|
|
|
private $viewer;
|
|
|
|
public function setViewer(PhabricatorUser $viewer) {
|
|
$this->viewer = $viewer;
|
|
return $this;
|
|
}
|
|
|
|
public function getViewer() {
|
|
return $this->viewer;
|
|
}
|
|
|
|
abstract public function getSettingName();
|
|
|
|
protected function getControlInstructions() {
|
|
return null;
|
|
}
|
|
|
|
protected function isEnabledForViewer(PhabricatorUser $viewer) {
|
|
return true;
|
|
}
|
|
|
|
public function getSettingDefaultValue() {
|
|
return null;
|
|
}
|
|
|
|
final public function getSettingKey() {
|
|
return $this->getPhobjectClassConstant('SETTINGKEY');
|
|
}
|
|
|
|
public static function getAllSettings() {
|
|
return id(new PhutilClassMapQuery())
|
|
->setAncestorClass(__CLASS__)
|
|
->setUniqueMethod('getSettingKey')
|
|
->execute();
|
|
}
|
|
|
|
public static function getAllEnabledSettings(PhabricatorUser $viewer) {
|
|
$settings = self::getAllSettings();
|
|
foreach ($settings as $key => $setting) {
|
|
if (!$setting->isEnabledForViewer($viewer)) {
|
|
unset($settings[$key]);
|
|
}
|
|
}
|
|
return $settings;
|
|
}
|
|
|
|
final public function newCustomEditFields($object) {
|
|
$fields = array();
|
|
|
|
$field = $this->newCustomEditField($object);
|
|
if ($field) {
|
|
$fields[] = $field;
|
|
}
|
|
|
|
return $fields;
|
|
}
|
|
|
|
protected function newCustomEditField($object) {
|
|
return null;
|
|
}
|
|
|
|
protected function newEditField($object, PhabricatorEditField $template) {
|
|
$setting_property = PhabricatorUserPreferencesTransaction::PROPERTY_SETTING;
|
|
$setting_key = $this->getSettingKey();
|
|
$value = $object->getPreference($setting_key);
|
|
$xaction_type = PhabricatorUserPreferencesTransaction::TYPE_SETTING;
|
|
$label = $this->getSettingName();
|
|
|
|
$template
|
|
->setKey($setting_key)
|
|
->setLabel($label)
|
|
->setValue($value)
|
|
->setTransactionType($xaction_type)
|
|
->setMetadataValue($setting_property, $setting_key);
|
|
|
|
$instructions = $this->getControlInstructions();
|
|
if (strlen($instructions)) {
|
|
$template->setControlInstructions($instructions);
|
|
}
|
|
|
|
return $template;
|
|
}
|
|
|
|
public function validateTransactionValue($value) {
|
|
return;
|
|
}
|
|
|
|
public function getTransactionNewValue($value) {
|
|
return $value;
|
|
}
|
|
|
|
}
|