Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / search / field / PhabricatorSearchCheckboxesField.php
blobce41f85db3fcd0d4418f58b7e72f4be8bda24e29
1 <?php
3 final class PhabricatorSearchCheckboxesField
4 extends PhabricatorSearchField {
6 private $options;
7 private $deprecatedOptions = array();
9 public function setOptions(array $options) {
10 $this->options = $options;
11 return $this;
14 public function getOptions() {
15 return $this->options;
18 public function setDeprecatedOptions(array $deprecated_options) {
19 $this->deprecatedOptions = $deprecated_options;
20 return $this;
23 public function getDeprecatedOptions() {
24 return $this->deprecatedOptions;
27 protected function getDefaultValue() {
28 return array();
31 protected function didReadValueFromSavedQuery($value) {
32 if (!is_array($value)) {
33 return array();
36 return $this->getCanonicalValue($value);
39 protected function getValueFromRequest(AphrontRequest $request, $key) {
40 $value = $this->getListFromRequest($request, $key);
41 return $this->getCanonicalValue($value);
44 protected function newControl() {
45 $value = array_fuse($this->getValue());
47 $control = new AphrontFormCheckboxControl();
48 foreach ($this->getOptions() as $key => $option) {
49 $control->addCheckbox(
50 $this->getKey().'[]',
51 $key,
52 $option,
53 isset($value[$key]));
56 return $control;
59 protected function newConduitParameterType() {
60 return new ConduitStringListParameterType();
63 public function newConduitConstants() {
64 $list = array();
66 foreach ($this->getOptions() as $key => $option) {
67 $list[] = id(new ConduitConstantDescription())
68 ->setKey($key)
69 ->setValue($option);
72 foreach ($this->getDeprecatedOptions() as $key => $value) {
73 $list[] = id(new ConduitConstantDescription())
74 ->setKey($key)
75 ->setIsDeprecated(true)
76 ->setValue(pht('Deprecated alias for "%s".', $value));
79 return $list;
82 private function getCanonicalValue(array $values) {
83 // Always map the current normal options to themselves.
84 $normal_options = array_fuse(array_keys($this->getOptions()));
86 // Map deprecated values to their new values.
87 $deprecated_options = $this->getDeprecatedOptions();
89 $map = $normal_options + $deprecated_options;
90 foreach ($values as $key => $value) {
91 $values[$key] = idx($map, $value, $value);
94 return $values;