mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-28 09:42:41 +01:00
149e6aaa21
Summary: Ref T12124. After D18134 we accept either "25" or "low" via HTTP parameters and when the field renders as a control, but if the form has a default value for the field but locks or hides it we don't actually run through that logic. Canonicalize both when rendering the control and when using a raw saved default value. Test Plan: - Created a form with "Priority: Low". - Hid the "Priority" field. - Before patch: Tried to create a task, was rebuffed with a (now verbose and helpful, after D18135) error. - Applied patch: things worked. Reviewers: chad, amckinley Reviewed By: amckinley Maniphest Tasks: T12124 Differential Revision: https://secure.phabricator.com/D18142
69 lines
1.6 KiB
PHP
69 lines
1.6 KiB
PHP
<?php
|
|
|
|
final class PhabricatorSelectEditField
|
|
extends PhabricatorEditField {
|
|
|
|
private $options;
|
|
private $optionAliases = array();
|
|
|
|
public function setOptions(array $options) {
|
|
$this->options = $options;
|
|
return $this;
|
|
}
|
|
|
|
public function getOptions() {
|
|
if ($this->options === null) {
|
|
throw new PhutilInvalidStateException('setOptions');
|
|
}
|
|
return $this->options;
|
|
}
|
|
|
|
public function setOptionAliases(array $option_aliases) {
|
|
$this->optionAliases = $option_aliases;
|
|
return $this;
|
|
}
|
|
|
|
public function getOptionAliases() {
|
|
return $this->optionAliases;
|
|
}
|
|
|
|
protected function getDefaultValueFromConfiguration($value) {
|
|
return $this->getCanonicalValue($value);
|
|
}
|
|
|
|
protected function getValueForControl() {
|
|
$value = parent::getValueForControl();
|
|
return $this->getCanonicalValue($value);
|
|
}
|
|
|
|
protected function newControl() {
|
|
return id(new AphrontFormSelectControl())
|
|
->setOptions($this->getOptions());
|
|
}
|
|
|
|
protected function newHTTPParameterType() {
|
|
return new AphrontSelectHTTPParameterType();
|
|
}
|
|
|
|
protected function newCommentAction() {
|
|
return id(new PhabricatorEditEngineSelectCommentAction())
|
|
->setOptions($this->getOptions());
|
|
}
|
|
|
|
protected function newConduitParameterType() {
|
|
return new ConduitStringParameterType();
|
|
}
|
|
|
|
private function getCanonicalValue($value) {
|
|
$options = $this->getOptions();
|
|
if (!isset($options[$value])) {
|
|
$aliases = $this->getOptionAliases();
|
|
if (isset($aliases[$value])) {
|
|
$value = $aliases[$value];
|
|
}
|
|
}
|
|
|
|
return $value;
|
|
}
|
|
|
|
}
|