2016-06-03 14:05:51 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
abstract class PhabricatorEditEngineSettingsPanel
|
|
|
|
extends PhabricatorSettingsPanel {
|
|
|
|
|
|
|
|
final public function processRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$user = $this->getUser();
|
|
|
|
|
2016-06-05 21:38:04 +02:00
|
|
|
if ($user && ($user->getPHID() === $viewer->getPHID())) {
|
2016-06-03 14:05:51 +02:00
|
|
|
$is_self = true;
|
|
|
|
} else {
|
|
|
|
$is_self = false;
|
|
|
|
}
|
|
|
|
|
2016-06-05 21:38:04 +02:00
|
|
|
if ($user && $user->getPHID()) {
|
2016-06-03 14:05:51 +02:00
|
|
|
$profile_uri = '/people/manage/'.$user->getID().'/';
|
|
|
|
} else {
|
|
|
|
$profile_uri = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$engine = id(new PhabricatorSettingsEditEngine())
|
|
|
|
->setController($this->getController())
|
|
|
|
->setNavigation($this->getNavigation())
|
|
|
|
->setIsSelfEdit($is_self)
|
|
|
|
->setProfileURI($profile_uri);
|
|
|
|
|
2016-06-05 21:38:04 +02:00
|
|
|
$preferences = $this->getPreferences();
|
2016-06-03 14:05:51 +02:00
|
|
|
|
|
|
|
$engine->setTargetObject($preferences);
|
|
|
|
|
|
|
|
return $engine->buildResponse();
|
|
|
|
}
|
|
|
|
|
2016-06-03 15:12:10 +02:00
|
|
|
final public function isEnabled() {
|
|
|
|
// Only enable the panel if it has any fields.
|
|
|
|
$field_keys = $this->getPanelSettingsKeys();
|
|
|
|
return (bool)$field_keys;
|
|
|
|
}
|
|
|
|
|
2016-06-03 14:05:51 +02:00
|
|
|
final public function newEditEnginePage() {
|
|
|
|
$field_keys = $this->getPanelSettingsKeys();
|
|
|
|
if (!$field_keys) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$key = $this->getPanelKey();
|
|
|
|
$label = $this->getPanelName();
|
2016-06-05 21:38:04 +02:00
|
|
|
$panel_uri = $this->getPanelURI();
|
2016-06-03 14:05:51 +02:00
|
|
|
|
|
|
|
return id(new PhabricatorEditPage())
|
|
|
|
->setKey($key)
|
|
|
|
->setLabel($label)
|
|
|
|
->setViewURI($panel_uri)
|
|
|
|
->setFieldKeys($field_keys);
|
|
|
|
}
|
|
|
|
|
|
|
|
final public function getPanelSettingsKeys() {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$settings = PhabricatorSetting::getAllEnabledSettings($viewer);
|
|
|
|
|
|
|
|
$this_key = $this->getPanelKey();
|
|
|
|
|
|
|
|
$panel_settings = array();
|
|
|
|
foreach ($settings as $setting) {
|
|
|
|
if ($setting->getSettingPanelKey() == $this_key) {
|
|
|
|
$panel_settings[] = $setting;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mpull($panel_settings, 'getSettingKey');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|