mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
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
This commit is contained in:
parent
5d54f26dac
commit
f0eefdd0b5
12 changed files with 56 additions and 15 deletions
|
@ -2976,6 +2976,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorEditEngineStaticCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineStaticCommentAction.php',
|
||||
'PhabricatorEditEngineSubtype' => 'applications/transactions/editengine/PhabricatorEditEngineSubtype.php',
|
||||
'PhabricatorEditEngineSubtypeInterface' => 'applications/transactions/editengine/PhabricatorEditEngineSubtypeInterface.php',
|
||||
'PhabricatorEditEngineSubtypeMap' => 'applications/transactions/editengine/PhabricatorEditEngineSubtypeMap.php',
|
||||
'PhabricatorEditEngineSubtypeTestCase' => 'applications/transactions/editengine/__tests__/PhabricatorEditEngineSubtypeTestCase.php',
|
||||
'PhabricatorEditEngineTokenizerCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineTokenizerCommentAction.php',
|
||||
'PhabricatorEditField' => 'applications/transactions/editfield/PhabricatorEditField.php',
|
||||
|
@ -8729,6 +8730,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorEditEngineSettingsPanel' => 'PhabricatorSettingsPanel',
|
||||
'PhabricatorEditEngineStaticCommentAction' => 'PhabricatorEditEngineCommentAction',
|
||||
'PhabricatorEditEngineSubtype' => 'Phobject',
|
||||
'PhabricatorEditEngineSubtypeMap' => 'Phobject',
|
||||
'PhabricatorEditEngineSubtypeTestCase' => 'PhabricatorTestCase',
|
||||
'PhabricatorEditEngineTokenizerCommentAction' => 'PhabricatorEditEngineCommentAction',
|
||||
'PhabricatorEditField' => 'Phobject',
|
||||
|
|
|
@ -47,7 +47,7 @@ final class ManiphestTaskSearchEngine
|
|||
// Hide the "Subtypes" constraint from the web UI if the install only
|
||||
// defines one task subtype, since it isn't of any use in this case.
|
||||
$subtype_map = id(new ManiphestTask())->newEditEngineSubtypeMap();
|
||||
$hide_subtypes = (count($subtype_map) == 1);
|
||||
$hide_subtypes = ($subtype_map->getCount() == 1);
|
||||
|
||||
return array(
|
||||
id(new PhabricatorOwnersSearchField())
|
||||
|
|
|
@ -573,7 +573,7 @@ final class ManiphestTask extends ManiphestDAO
|
|||
public function newSubtypeObject() {
|
||||
$subtype_key = $this->getEditEngineSubtype();
|
||||
$subtype_map = $this->newEditEngineSubtypeMap();
|
||||
return idx($subtype_map, $subtype_key);
|
||||
return $subtype_map->getSubtype($subtype_key);
|
||||
}
|
||||
|
||||
/* -( PhabricatorFulltextInterface )--------------------------------------- */
|
||||
|
|
|
@ -214,11 +214,12 @@ final class ManiphestTransaction
|
|||
public function renderSubtypeName($value) {
|
||||
$object = $this->getObject();
|
||||
$map = $object->newEditEngineSubtypeMap();
|
||||
if (!isset($map[$value])) {
|
||||
|
||||
if (!$map->isValidSubtype($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return $map[$value]->getName();
|
||||
return $map->getSubtype($value)->getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ final class ManiphestTaskSubtypeDatasource
|
|||
$results = array();
|
||||
|
||||
$subtype_map = id(new ManiphestTask())->newEditEngineSubtypeMap();
|
||||
foreach ($subtype_map as $key => $subtype) {
|
||||
foreach ($subtype_map->getSubtypes() as $key => $subtype) {
|
||||
|
||||
$result = id(new PhabricatorTypeaheadResult())
|
||||
->setIcon($subtype->getIcon())
|
||||
|
|
|
@ -56,9 +56,6 @@ final class ManiphestTaskListView extends ManiphestView {
|
|||
Javelin::initBehavior('maniphest-list-editor');
|
||||
}
|
||||
|
||||
$subtype_map = id(new ManiphestTask())
|
||||
->newEditEngineSubtypeMap();
|
||||
|
||||
foreach ($this->tasks as $task) {
|
||||
$item = id(new PHUIObjectItemView())
|
||||
->setUser($this->getUser())
|
||||
|
|
|
@ -61,8 +61,7 @@ Choose the object **subtype** that this form should create and edit.
|
|||
EOTEXT
|
||||
);
|
||||
|
||||
$map = $engine->newSubtypeMap();
|
||||
$map = mpull($map, 'getName');
|
||||
$map = $engine->newSubtypeMap()->getDisplayMap();
|
||||
|
||||
$form = id(new AphrontFormView())
|
||||
->setUser($viewer)
|
||||
|
|
|
@ -182,7 +182,7 @@ final class PhabricatorEditEngineSubtype
|
|||
$map[$key] = $subtype;
|
||||
}
|
||||
|
||||
return $map;
|
||||
return new PhabricatorEditEngineSubtypeMap($map);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
|
||||
final class PhabricatorEditEngineSubtypeMap
|
||||
extends Phobject {
|
||||
|
||||
private $subtypes;
|
||||
|
||||
public function __construct(array $subtypes) {
|
||||
assert_instances_of($subtypes, 'PhabricatorEditEngineSubtype');
|
||||
|
||||
$this->subtypes = $subtypes;
|
||||
}
|
||||
|
||||
public function getDisplayMap() {
|
||||
return mpull($this->subtypes, 'getName');
|
||||
}
|
||||
|
||||
public function getCount() {
|
||||
return count($this->subtypes);
|
||||
}
|
||||
|
||||
public function isValidSubtype($subtype_key) {
|
||||
return isset($this->subtypes[$subtype_key]);
|
||||
}
|
||||
|
||||
public function getSubtypes() {
|
||||
return $this->subtypes;
|
||||
}
|
||||
|
||||
public function getSubtype($subtype_key) {
|
||||
if (!$this->isValidSubtype($subtype_key)) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Subtype key "%s" does not identify a valid subtype.',
|
||||
$subtype_key));
|
||||
}
|
||||
|
||||
return $this->subtypes[$subtype_key];
|
||||
}
|
||||
|
||||
}
|
|
@ -2541,7 +2541,7 @@ abstract class PhabricatorApplicationTransactionEditor
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!isset($map[$new])) {
|
||||
if (!$map->isValidSubtype($new)) {
|
||||
$errors[] = new PhabricatorApplicationTransactionValidationError(
|
||||
$transaction_type,
|
||||
pht('Invalid'),
|
||||
|
|
|
@ -64,7 +64,7 @@ final class PhabricatorEditEngineConfigurationEditor
|
|||
foreach ($xactions as $xaction) {
|
||||
$new = $xaction->getNewValue();
|
||||
|
||||
if (isset($map[$new])) {
|
||||
if ($map->isValidSubtype($new)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ final class PhabricatorSubtypeEditEngineExtension
|
|||
$subtype_type = PhabricatorTransactions::TYPE_SUBTYPE;
|
||||
|
||||
$map = $object->newEditEngineSubtypeMap();
|
||||
$options = mpull($map, 'getName');
|
||||
$options = $map->getDisplayMap();
|
||||
|
||||
$subtype_field = id(new PhabricatorSelectEditField())
|
||||
->setKey(self::EDITKEY)
|
||||
|
@ -45,7 +45,7 @@ final class PhabricatorSubtypeEditEngineExtension
|
|||
|
||||
// If subtypes are configured, enable changing them from the bulk editor
|
||||
// and comment action stack.
|
||||
if (count($map) > 1) {
|
||||
if ($map->getCount() > 1) {
|
||||
$subtype_field
|
||||
->setBulkEditLabel(pht('Change subtype to'))
|
||||
->setCommentActionLabel(pht('Change Subtype'))
|
||||
|
|
Loading…
Reference in a new issue