@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Allow numeric constants to act as aliases for task priorities in the web UI <select />

Summary:
Ref T12124. This is a fairly narrow fix for existing saved EditEngine forms with a default priority value.

These saved forms have a numeric (or probably "string-numeric") default value, like "50". They lost their meaning after D18111, when "50" no longer appears in the dropdown. Instead, these forms all select the highest available priority.

At time of writing, this form was broken on this install, for example:

> https://secure.phabricator.com/transactions/editengine/maniphest.task/view/13/

Additionally, `/task/edit/form/123/?priority=...` (for templating forms) stopped working with `priority=50`. This isn't nearly as important, but a larger and more sudden compatiblity break than we need to make.

Add support for an "alias map" on `<select />` controls, so if the value comes in with something we don't recognize we'll treat it like some other value. Then alias all the numeric constants -- and other keywords -- to the right constants.

This ended up only affecting the `<select />` control in the web UI.

Test Plan:
- On `stable`, created a form with "Priority: Low".
- Before patch: form has "Priority: Unbreak Now!" on `master`.
- After patch: form has "Priority: Low" again.
- Used `?priority=25`, `?priority=wish`, `?priority=wishlist` to template forms: all forms worked.

Reviewers: amckinley, chad

Reviewed By: amckinley

Maniphest Tasks: T12124

Differential Revision: https://secure.phabricator.com/D18134

+86 -4
+52
src/applications/maniphest/constants/ManiphestTaskPriority.php
··· 43 43 return $map; 44 44 } 45 45 46 + /** 47 + * Get the canonical keyword for a given priority constant. 48 + * 49 + * @return string|null Keyword, or `null` if no keyword is configured. 50 + */ 51 + public static function getKeywordForTaskPriority($priority) { 52 + $map = self::getConfig(); 53 + 54 + $spec = idx($map, $priority); 55 + if (!$spec) { 56 + return null; 57 + } 58 + 59 + $keywords = idx($spec, 'keywords'); 60 + if (!$keywords) { 61 + return null; 62 + } 63 + 64 + return head($keywords); 65 + } 66 + 67 + 68 + /** 69 + * Get a map of supported alternate names for each priority. 70 + * 71 + * Keys are aliases, like "wish" and "wishlist". Values are canonical 72 + * priority keywords, like "wishlist". 73 + * 74 + * @return map<string, string> Map of aliases to canonical priority keywords. 75 + */ 76 + public static function getTaskPriorityAliasMap() { 77 + $keyword_map = self::getTaskPriorityKeywordsMap(); 78 + 79 + $result = array(); 80 + foreach ($keyword_map as $key => $keywords) { 81 + $target = self::getKeywordForTaskPriority($key); 82 + if ($target === null) { 83 + continue; 84 + } 85 + 86 + // NOTE: Include the raw priority value, like "25", in the list of 87 + // aliases. This supports legacy sources like saved EditEngine forms. 88 + $result[$key] = $target; 89 + 90 + foreach ($keywords as $keyword) { 91 + $result[$keyword] = $target; 92 + } 93 + } 94 + 95 + return $result; 96 + } 97 + 46 98 47 99 /** 48 100 * Get the priorities and their related short (one-word) descriptions.
+3
src/applications/maniphest/editor/ManiphestEditEngine.php
··· 77 77 $status_map = $this->getTaskStatusMap($object); 78 78 $priority_map = $this->getTaskPriorityMap($object); 79 79 80 + $alias_map = ManiphestTaskPriority::getTaskPriorityAliasMap(); 81 + 80 82 if ($object->isClosed()) { 81 83 $default_status = ManiphestTaskStatus::getDefaultStatus(); 82 84 } else { ··· 217 219 ->setIsCopyable(true) 218 220 ->setValue($object->getPriorityKeyword()) 219 221 ->setOptions($priority_map) 222 + ->setOptionAliases($alias_map) 220 223 ->setCommentActionLabel(pht('Change Priority')), 221 224 ); 222 225
+7 -4
src/applications/maniphest/storage/ManiphestTask.php
··· 247 247 248 248 public function getPriorityKeyword() { 249 249 $priority = $this->getPriority(); 250 - $map = ManiphestTaskPriority::getTaskPriorityKeywordsMap(); 251 - $default = array(ManiphestTaskPriority::UNKNOWN_PRIORITY_KEYWORD); 252 - $keywords = idx($map, $priority, $default); 253 - return head($keywords); 250 + 251 + $keyword = ManiphestTaskPriority::getKeywordForTaskPriority($priority); 252 + if ($keyword !== null) { 253 + return $keyword; 254 + } 255 + 256 + return ManiphestTaskPriority::UNKNOWN_PRIORITY_KEYWORD; 254 257 } 255 258 256 259 private function comparePriorityTo(ManiphestTask $other) {
+24
src/applications/transactions/editfield/PhabricatorSelectEditField.php
··· 4 4 extends PhabricatorEditField { 5 5 6 6 private $options; 7 + private $optionAliases = array(); 7 8 8 9 public function setOptions(array $options) { 9 10 $this->options = $options; ··· 15 16 throw new PhutilInvalidStateException('setOptions'); 16 17 } 17 18 return $this->options; 19 + } 20 + 21 + public function setOptionAliases(array $option_aliases) { 22 + $this->optionAliases = $option_aliases; 23 + return $this; 24 + } 25 + 26 + public function getOptionAliases() { 27 + return $this->optionAliases; 28 + } 29 + 30 + protected function getValueForControl() { 31 + $value = parent::getValueForControl(); 32 + 33 + $options = $this->getOptions(); 34 + if (!isset($options[$value])) { 35 + $aliases = $this->getOptionAliases(); 36 + if (isset($aliases[$value])) { 37 + $value = $aliases[$value]; 38 + } 39 + } 40 + 41 + return $value; 18 42 } 19 43 20 44 protected function newControl() {