Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/field/PhabricatorSearchCheckboxesField.php
<?php | <?php | ||||
final class PhabricatorSearchCheckboxesField | final class PhabricatorSearchCheckboxesField | ||||
extends PhabricatorSearchField { | extends PhabricatorSearchField { | ||||
private $options; | private $options; | ||||
private $deprecatedOptions = array(); | |||||
public function setOptions(array $options) { | public function setOptions(array $options) { | ||||
$this->options = $options; | $this->options = $options; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getOptions() { | public function getOptions() { | ||||
return $this->options; | return $this->options; | ||||
} | } | ||||
public function setDeprecatedOptions(array $deprecated_options) { | |||||
$this->deprecatedOptions = $deprecated_options; | |||||
return $this; | |||||
} | |||||
public function getDeprecatedOptions() { | |||||
return $this->deprecatedOptions; | |||||
} | |||||
protected function getDefaultValue() { | protected function getDefaultValue() { | ||||
return array(); | return array(); | ||||
} | } | ||||
protected function didReadValueFromSavedQuery($value) { | protected function didReadValueFromSavedQuery($value) { | ||||
if (!is_array($value)) { | if (!is_array($value)) { | ||||
return array(); | return array(); | ||||
} | } | ||||
return $value; | return $this->getCanonicalValue($value); | ||||
} | } | ||||
protected function getValueFromRequest(AphrontRequest $request, $key) { | protected function getValueFromRequest(AphrontRequest $request, $key) { | ||||
return $this->getListFromRequest($request, $key); | $value = $this->getListFromRequest($request, $key); | ||||
return $this->getCanonicalValue($value); | |||||
} | } | ||||
protected function newControl() { | protected function newControl() { | ||||
$value = array_fuse($this->getValue()); | $value = array_fuse($this->getValue()); | ||||
$control = new AphrontFormCheckboxControl(); | $control = new AphrontFormCheckboxControl(); | ||||
foreach ($this->getOptions() as $key => $option) { | foreach ($this->getOptions() as $key => $option) { | ||||
$control->addCheckbox( | $control->addCheckbox( | ||||
Show All 14 Lines | public function newConduitConstants() { | ||||
$list = array(); | $list = array(); | ||||
foreach ($this->getOptions() as $key => $option) { | foreach ($this->getOptions() as $key => $option) { | ||||
$list[] = id(new ConduitConstantDescription()) | $list[] = id(new ConduitConstantDescription()) | ||||
->setKey($key) | ->setKey($key) | ||||
->setValue($option); | ->setValue($option); | ||||
} | } | ||||
foreach ($this->getDeprecatedOptions() as $key => $value) { | |||||
$list[] = id(new ConduitConstantDescription()) | |||||
->setKey($key) | |||||
->setIsDeprecated(true) | |||||
->setValue(pht('Deprecated alias for "%s".', $value)); | |||||
} | |||||
return $list; | return $list; | ||||
} | } | ||||
private function getCanonicalValue(array $values) { | |||||
// Always map the current normal options to themselves. | |||||
$normal_options = array_fuse(array_keys($this->getOptions())); | |||||
// Map deprecated values to their new values. | |||||
$deprecated_options = $this->getDeprecatedOptions(); | |||||
$map = $normal_options + $deprecated_options; | |||||
foreach ($values as $key => $value) { | |||||
$values[$key] = idx($map, $value, $value); | |||||
} | |||||
return $values; | |||||
} | |||||
} | } |