@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.

Replace the informal "array" subtype map with a more formal "SubtypeMap" object

Summary: Ref T13222. Ref T12588. See PHI683. To make "Create Subtask..." fancier, we need slightly more logic around subtype maps. Upgrade the plain old array into a proper object so it can have relevant methods, notably "get a list of valid child subtypes for some parent subtype".

Test Plan: Created and edited tasks, changed task subtypes. Grepped for affected symbols (`newEditEngineSubtypeMap`, `newSubtypeMap`).

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13222, T12588

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

+56 -15
+2
src/__phutil_library_map__.php
··· 2976 2976 'PhabricatorEditEngineStaticCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineStaticCommentAction.php', 2977 2977 'PhabricatorEditEngineSubtype' => 'applications/transactions/editengine/PhabricatorEditEngineSubtype.php', 2978 2978 'PhabricatorEditEngineSubtypeInterface' => 'applications/transactions/editengine/PhabricatorEditEngineSubtypeInterface.php', 2979 + 'PhabricatorEditEngineSubtypeMap' => 'applications/transactions/editengine/PhabricatorEditEngineSubtypeMap.php', 2979 2980 'PhabricatorEditEngineSubtypeTestCase' => 'applications/transactions/editengine/__tests__/PhabricatorEditEngineSubtypeTestCase.php', 2980 2981 'PhabricatorEditEngineTokenizerCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineTokenizerCommentAction.php', 2981 2982 'PhabricatorEditField' => 'applications/transactions/editfield/PhabricatorEditField.php', ··· 8729 8730 'PhabricatorEditEngineSettingsPanel' => 'PhabricatorSettingsPanel', 8730 8731 'PhabricatorEditEngineStaticCommentAction' => 'PhabricatorEditEngineCommentAction', 8731 8732 'PhabricatorEditEngineSubtype' => 'Phobject', 8733 + 'PhabricatorEditEngineSubtypeMap' => 'Phobject', 8732 8734 'PhabricatorEditEngineSubtypeTestCase' => 'PhabricatorTestCase', 8733 8735 'PhabricatorEditEngineTokenizerCommentAction' => 'PhabricatorEditEngineCommentAction', 8734 8736 'PhabricatorEditField' => 'Phobject',
+1 -1
src/applications/maniphest/query/ManiphestTaskSearchEngine.php
··· 47 47 // Hide the "Subtypes" constraint from the web UI if the install only 48 48 // defines one task subtype, since it isn't of any use in this case. 49 49 $subtype_map = id(new ManiphestTask())->newEditEngineSubtypeMap(); 50 - $hide_subtypes = (count($subtype_map) == 1); 50 + $hide_subtypes = ($subtype_map->getCount() == 1); 51 51 52 52 return array( 53 53 id(new PhabricatorOwnersSearchField())
+1 -1
src/applications/maniphest/storage/ManiphestTask.php
··· 573 573 public function newSubtypeObject() { 574 574 $subtype_key = $this->getEditEngineSubtype(); 575 575 $subtype_map = $this->newEditEngineSubtypeMap(); 576 - return idx($subtype_map, $subtype_key); 576 + return $subtype_map->getSubtype($subtype_key); 577 577 } 578 578 579 579 /* -( PhabricatorFulltextInterface )--------------------------------------- */
+3 -2
src/applications/maniphest/storage/ManiphestTransaction.php
··· 214 214 public function renderSubtypeName($value) { 215 215 $object = $this->getObject(); 216 216 $map = $object->newEditEngineSubtypeMap(); 217 - if (!isset($map[$value])) { 217 + 218 + if (!$map->isValidSubtype($value)) { 218 219 return $value; 219 220 } 220 221 221 - return $map[$value]->getName(); 222 + return $map->getSubtype($value)->getName(); 222 223 } 223 224 224 225 }
+1 -1
src/applications/maniphest/typeahead/ManiphestTaskSubtypeDatasource.php
··· 28 28 $results = array(); 29 29 30 30 $subtype_map = id(new ManiphestTask())->newEditEngineSubtypeMap(); 31 - foreach ($subtype_map as $key => $subtype) { 31 + foreach ($subtype_map->getSubtypes() as $key => $subtype) { 32 32 33 33 $result = id(new PhabricatorTypeaheadResult()) 34 34 ->setIcon($subtype->getIcon())
-3
src/applications/maniphest/view/ManiphestTaskListView.php
··· 56 56 Javelin::initBehavior('maniphest-list-editor'); 57 57 } 58 58 59 - $subtype_map = id(new ManiphestTask()) 60 - ->newEditEngineSubtypeMap(); 61 - 62 59 foreach ($this->tasks as $task) { 63 60 $item = id(new PHUIObjectItemView()) 64 61 ->setUser($this->getUser())
+1 -2
src/applications/transactions/controller/PhabricatorEditEngineConfigurationSubtypeController.php
··· 61 61 EOTEXT 62 62 ); 63 63 64 - $map = $engine->newSubtypeMap(); 65 - $map = mpull($map, 'getName'); 64 + $map = $engine->newSubtypeMap()->getDisplayMap(); 66 65 67 66 $form = id(new AphrontFormView()) 68 67 ->setUser($viewer)
+1 -1
src/applications/transactions/editengine/PhabricatorEditEngineSubtype.php
··· 182 182 $map[$key] = $subtype; 183 183 } 184 184 185 - return $map; 185 + return new PhabricatorEditEngineSubtypeMap($map); 186 186 } 187 187 188 188 }
+42
src/applications/transactions/editengine/PhabricatorEditEngineSubtypeMap.php
··· 1 + <?php 2 + 3 + 4 + final class PhabricatorEditEngineSubtypeMap 5 + extends Phobject { 6 + 7 + private $subtypes; 8 + 9 + public function __construct(array $subtypes) { 10 + assert_instances_of($subtypes, 'PhabricatorEditEngineSubtype'); 11 + 12 + $this->subtypes = $subtypes; 13 + } 14 + 15 + public function getDisplayMap() { 16 + return mpull($this->subtypes, 'getName'); 17 + } 18 + 19 + public function getCount() { 20 + return count($this->subtypes); 21 + } 22 + 23 + public function isValidSubtype($subtype_key) { 24 + return isset($this->subtypes[$subtype_key]); 25 + } 26 + 27 + public function getSubtypes() { 28 + return $this->subtypes; 29 + } 30 + 31 + public function getSubtype($subtype_key) { 32 + if (!$this->isValidSubtype($subtype_key)) { 33 + throw new Exception( 34 + pht( 35 + 'Subtype key "%s" does not identify a valid subtype.', 36 + $subtype_key)); 37 + } 38 + 39 + return $this->subtypes[$subtype_key]; 40 + } 41 + 42 + }
+1 -1
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 2541 2541 continue; 2542 2542 } 2543 2543 2544 - if (!isset($map[$new])) { 2544 + if (!$map->isValidSubtype($new)) { 2545 2545 $errors[] = new PhabricatorApplicationTransactionValidationError( 2546 2546 $transaction_type, 2547 2547 pht('Invalid'),
+1 -1
src/applications/transactions/editor/PhabricatorEditEngineConfigurationEditor.php
··· 64 64 foreach ($xactions as $xaction) { 65 65 $new = $xaction->getNewValue(); 66 66 67 - if (isset($map[$new])) { 67 + if ($map->isValidSubtype($new)) { 68 68 continue; 69 69 } 70 70
+2 -2
src/applications/transactions/engineextension/PhabricatorSubtypeEditEngineExtension.php
··· 31 31 $subtype_type = PhabricatorTransactions::TYPE_SUBTYPE; 32 32 33 33 $map = $object->newEditEngineSubtypeMap(); 34 - $options = mpull($map, 'getName'); 34 + $options = $map->getDisplayMap(); 35 35 36 36 $subtype_field = id(new PhabricatorSelectEditField()) 37 37 ->setKey(self::EDITKEY) ··· 45 45 46 46 // If subtypes are configured, enable changing them from the bulk editor 47 47 // and comment action stack. 48 - if (count($map) > 1) { 48 + if ($map->getCount() > 1) { 49 49 $subtype_field 50 50 ->setBulkEditLabel(pht('Change subtype to')) 51 51 ->setCommentActionLabel(pht('Change Subtype'))