Skip to content

Commit 1b96f2f

Browse files
author
epriestley
committedMar 2, 2017
Add maniphest.subtypes for configuring task subtypes
Summary: Ref T12314. Builds toward letting you define "animal" and "plant" tasks. This just adds some configuration. I'll probably add some more quality-of-life options (like "icon") later but these are the only bits I'm sure I'll need. Test Plan: - Configured sensible subtypes. - Tried to configure bad subtypes: bad key, missing "default", duplicate keys. Got sensible error messages. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12314 Differential Revision: https://secure.phabricator.com/D17440
1 parent 91ef237 commit 1b96f2f

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed
 

‎src/__phutil_library_map__.php

+2
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,7 @@
14711471
'ManiphestStatusConfigOptionType' => 'applications/maniphest/config/ManiphestStatusConfigOptionType.php',
14721472
'ManiphestStatusEmailCommand' => 'applications/maniphest/command/ManiphestStatusEmailCommand.php',
14731473
'ManiphestSubpriorityController' => 'applications/maniphest/controller/ManiphestSubpriorityController.php',
1474+
'ManiphestSubtypesConfigOptionsType' => 'applications/maniphest/config/ManiphestSubtypesConfigOptionsType.php',
14741475
'ManiphestTask' => 'applications/maniphest/storage/ManiphestTask.php',
14751476
'ManiphestTaskAssignHeraldAction' => 'applications/maniphest/herald/ManiphestTaskAssignHeraldAction.php',
14761477
'ManiphestTaskAssignOtherHeraldAction' => 'applications/maniphest/herald/ManiphestTaskAssignOtherHeraldAction.php',
@@ -6348,6 +6349,7 @@
63486349
'ManiphestStatusConfigOptionType' => 'PhabricatorConfigJSONOptionType',
63496350
'ManiphestStatusEmailCommand' => 'ManiphestEmailCommand',
63506351
'ManiphestSubpriorityController' => 'ManiphestController',
6352+
'ManiphestSubtypesConfigOptionsType' => 'PhabricatorConfigJSONOptionType',
63516353
'ManiphestTask' => array(
63526354
'ManiphestDAO',
63536355
'PhabricatorSubscribableInterface',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
final class ManiphestSubtypesConfigOptionsType
4+
extends PhabricatorConfigJSONOptionType {
5+
6+
public function validateOption(PhabricatorConfigOption $option, $value) {
7+
PhabricatorEditEngineSubtype::validateConfiguration($value);
8+
}
9+
10+
}

‎src/applications/maniphest/config/PhabricatorManiphestConfigOptions.php

+48
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,50 @@ public function getOptions() {
297297
EOTEXT
298298
));
299299

300+
$subtype_type = 'custom:ManiphestSubtypesConfigOptionsType';
301+
$subtype_default_key = PhabricatorEditEngineSubtype::SUBTYPE_DEFAULT;
302+
$subtype_example = array(
303+
array(
304+
'key' => $subtype_default_key,
305+
'name' => pht('Task'),
306+
),
307+
array(
308+
'key' => 'bug',
309+
'name' => pht('Bug'),
310+
),
311+
array(
312+
'key' => 'feature',
313+
'name' => pht('Feature Request'),
314+
),
315+
);
316+
$subtype_example = id(new PhutilJSON())->encodeAsList($subtype_example);
317+
318+
$subtype_default = array(
319+
array(
320+
'key' => $subtype_default_key,
321+
'name' => pht('Task'),
322+
),
323+
);
324+
325+
$subtype_description = $this->deformat(pht(<<<EOTEXT
326+
Allows you to define task subtypes. Subtypes let you hide fields you don't
327+
need to simplify the workflows for editing tasks.
328+
329+
To define subtypes, provide a list of subtypes. Each subtype should be a
330+
dictionary with these keys:
331+
332+
- `key` //Required string.// Internal identifier for the subtype, like
333+
"task", "feature", or "bug".
334+
- `name` //Required string.// Human-readable name for this subtype, like
335+
"Task", "Feature Request" or "Bug Report".
336+
337+
Each subtype must have a unique key, and you must define a subtype with
338+
the key "%s", which is used as a default subtype.
339+
EOTEXT
340+
,
341+
$subtype_default_key));
342+
343+
300344
return array(
301345
$this->newOption('maniphest.custom-field-definitions', 'wild', array())
302346
->setSummary(pht('Custom Maniphest fields.'))
@@ -361,6 +405,10 @@ public function getOptions() {
361405
->setDescription($points_description)
362406
->addExample($points_json_1, pht('Points Config'))
363407
->addExample($points_json_2, pht('Hours Config')),
408+
$this->newOption('maniphest.subtypes', $subtype_type, $subtype_default)
409+
->setSummary(pht('Define task subtypes.'))
410+
->setDescription($subtype_description)
411+
->addExample($subtype_example, pht('Simple Subtypes')),
364412
);
365413
}
366414

‎src/applications/transactions/editengine/PhabricatorEditEngineSubtype.php

+48
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,53 @@ public static function validateSubtypeKey($subtype) {
3232
}
3333
}
3434

35+
public static function validateConfiguration($config) {
36+
if (!is_array($config)) {
37+
throw new Exception(
38+
pht(
39+
'Subtype configuration is invalid: it must be a list of subtype '.
40+
'specifications.'));
41+
}
42+
43+
$map = array();
44+
foreach ($config as $value) {
45+
PhutilTypeSpec::checkMap(
46+
$value,
47+
array(
48+
'key' => 'string',
49+
'name' => 'string',
50+
));
51+
52+
$key = $value['key'];
53+
self::validateSubtypeKey($key);
54+
55+
if (isset($map[$key])) {
56+
throw new Exception(
57+
pht(
58+
'Subtype configuration is invalid: two subtypes use the same '.
59+
'key ("%s"). Each subtype must have a unique key.',
60+
$key));
61+
}
62+
63+
$map[$key] = true;
64+
65+
$name = $value['name'];
66+
if (!strlen($name)) {
67+
throw new Exception(
68+
pht(
69+
'Subtype configuration is invalid: subtype with key "%s" has '.
70+
'no name. Subtypes must have a name.',
71+
$key));
72+
}
73+
}
74+
75+
if (!isset($map[self::SUBTYPE_DEFAULT])) {
76+
throw new Exception(
77+
pht(
78+
'Subtype configuration is invalid: there is no subtype defined '.
79+
'with key "%s". This subtype is required and must be defined.',
80+
self::SUBTYPE_DEFAULT));
81+
}
82+
}
3583

3684
}

0 commit comments

Comments
 (0)
Failed to load comments.