diff --git a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php index 716b1e5c2a..5d0f79e170 100644 --- a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php +++ b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php @@ -269,6 +269,7 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject { $fields[] = id(new PhabricatorSearchOrderField()) ->setLabel(pht('Order By')) ->setKey('order') + ->setOrderAliases($query->getBuiltinOrderAliasMap()) ->setOptions($orders); } diff --git a/src/applications/search/field/PhabricatorSearchOrderField.php b/src/applications/search/field/PhabricatorSearchOrderField.php index 98e3b2beb3..70b94d1b35 100644 --- a/src/applications/search/field/PhabricatorSearchOrderField.php +++ b/src/applications/search/field/PhabricatorSearchOrderField.php @@ -4,6 +4,16 @@ final class PhabricatorSearchOrderField extends PhabricatorSearchField { private $options; + private $orderAliases; + + public function setOrderAliases(array $order_aliases) { + $this->orderAliases = $order_aliases; + return $this; + } + + public function getOrderAliases() { + return $this->orderAliases; + } public function setOptions(array $options) { $this->options = $options; @@ -22,6 +32,16 @@ final class PhabricatorSearchOrderField return $request->getStr($key); } + protected function getValueForControl() { + // If the SavedQuery has an alias for an order, map it to the canonical + // name for the order so the correct option is selected in the dropdown. + $value = parent::getValueForControl(); + if (isset($this->orderAliases[$value])) { + $value = $this->orderAliases[$value]; + } + return $value; + } + protected function newControl() { return id(new AphrontFormSelectControl()) ->setOptions($this->getOptions());