Page MenuHomePhabricator

D17440.id.diff
No OneTemporary

D17440.id.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1471,6 +1471,7 @@
'ManiphestStatusConfigOptionType' => 'applications/maniphest/config/ManiphestStatusConfigOptionType.php',
'ManiphestStatusEmailCommand' => 'applications/maniphest/command/ManiphestStatusEmailCommand.php',
'ManiphestSubpriorityController' => 'applications/maniphest/controller/ManiphestSubpriorityController.php',
+ 'ManiphestSubtypesConfigOptionsType' => 'applications/maniphest/config/ManiphestSubtypesConfigOptionsType.php',
'ManiphestTask' => 'applications/maniphest/storage/ManiphestTask.php',
'ManiphestTaskAssignHeraldAction' => 'applications/maniphest/herald/ManiphestTaskAssignHeraldAction.php',
'ManiphestTaskAssignOtherHeraldAction' => 'applications/maniphest/herald/ManiphestTaskAssignOtherHeraldAction.php',
@@ -6348,6 +6349,7 @@
'ManiphestStatusConfigOptionType' => 'PhabricatorConfigJSONOptionType',
'ManiphestStatusEmailCommand' => 'ManiphestEmailCommand',
'ManiphestSubpriorityController' => 'ManiphestController',
+ 'ManiphestSubtypesConfigOptionsType' => 'PhabricatorConfigJSONOptionType',
'ManiphestTask' => array(
'ManiphestDAO',
'PhabricatorSubscribableInterface',
diff --git a/src/applications/maniphest/config/ManiphestSubtypesConfigOptionsType.php b/src/applications/maniphest/config/ManiphestSubtypesConfigOptionsType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/maniphest/config/ManiphestSubtypesConfigOptionsType.php
@@ -0,0 +1,10 @@
+<?php
+
+final class ManiphestSubtypesConfigOptionsType
+ extends PhabricatorConfigJSONOptionType {
+
+ public function validateOption(PhabricatorConfigOption $option, $value) {
+ PhabricatorEditEngineSubtype::validateConfiguration($value);
+ }
+
+}
diff --git a/src/applications/maniphest/config/PhabricatorManiphestConfigOptions.php b/src/applications/maniphest/config/PhabricatorManiphestConfigOptions.php
--- a/src/applications/maniphest/config/PhabricatorManiphestConfigOptions.php
+++ b/src/applications/maniphest/config/PhabricatorManiphestConfigOptions.php
@@ -297,6 +297,50 @@
EOTEXT
));
+ $subtype_type = 'custom:ManiphestSubtypesConfigOptionsType';
+ $subtype_default_key = PhabricatorEditEngineSubtype::SUBTYPE_DEFAULT;
+ $subtype_example = array(
+ array(
+ 'key' => $subtype_default_key,
+ 'name' => pht('Task'),
+ ),
+ array(
+ 'key' => 'bug',
+ 'name' => pht('Bug'),
+ ),
+ array(
+ 'key' => 'feature',
+ 'name' => pht('Feature Request'),
+ ),
+ );
+ $subtype_example = id(new PhutilJSON())->encodeAsList($subtype_example);
+
+ $subtype_default = array(
+ array(
+ 'key' => $subtype_default_key,
+ 'name' => pht('Task'),
+ ),
+ );
+
+ $subtype_description = $this->deformat(pht(<<<EOTEXT
+Allows you to define task subtypes. Subtypes let you hide fields you don't
+need to simplify the workflows for editing tasks.
+
+To define subtypes, provide a list of subtypes. Each subtype should be a
+dictionary with these keys:
+
+ - `key` //Required string.// Internal identifier for the subtype, like
+ "task", "feature", or "bug".
+ - `name` //Required string.// Human-readable name for this subtype, like
+ "Task", "Feature Request" or "Bug Report".
+
+Each subtype must have a unique key, and you must define a subtype with
+the key "%s", which is used as a default subtype.
+EOTEXT
+ ,
+ $subtype_default_key));
+
+
return array(
$this->newOption('maniphest.custom-field-definitions', 'wild', array())
->setSummary(pht('Custom Maniphest fields.'))
@@ -361,6 +405,10 @@
->setDescription($points_description)
->addExample($points_json_1, pht('Points Config'))
->addExample($points_json_2, pht('Hours Config')),
+ $this->newOption('maniphest.subtypes', $subtype_type, $subtype_default)
+ ->setSummary(pht('Define task subtypes.'))
+ ->setDescription($subtype_description)
+ ->addExample($subtype_example, pht('Simple Subtypes')),
);
}
diff --git a/src/applications/transactions/editengine/PhabricatorEditEngineSubtype.php b/src/applications/transactions/editengine/PhabricatorEditEngineSubtype.php
--- a/src/applications/transactions/editengine/PhabricatorEditEngineSubtype.php
+++ b/src/applications/transactions/editengine/PhabricatorEditEngineSubtype.php
@@ -32,5 +32,53 @@
}
}
+ public static function validateConfiguration($config) {
+ if (!is_array($config)) {
+ throw new Exception(
+ pht(
+ 'Subtype configuration is invalid: it must be a list of subtype '.
+ 'specifications.'));
+ }
+
+ $map = array();
+ foreach ($config as $value) {
+ PhutilTypeSpec::checkMap(
+ $value,
+ array(
+ 'key' => 'string',
+ 'name' => 'string',
+ ));
+
+ $key = $value['key'];
+ self::validateSubtypeKey($key);
+
+ if (isset($map[$key])) {
+ throw new Exception(
+ pht(
+ 'Subtype configuration is invalid: two subtypes use the same '.
+ 'key ("%s"). Each subtype must have a unique key.',
+ $key));
+ }
+
+ $map[$key] = true;
+
+ $name = $value['name'];
+ if (!strlen($name)) {
+ throw new Exception(
+ pht(
+ 'Subtype configuration is invalid: subtype with key "%s" has '.
+ 'no name. Subtypes must have a name.',
+ $key));
+ }
+ }
+
+ if (!isset($map[self::SUBTYPE_DEFAULT])) {
+ throw new Exception(
+ pht(
+ 'Subtype configuration is invalid: there is no subtype defined '.
+ 'with key "%s". This subtype is required and must be defined.',
+ self::SUBTYPE_DEFAULT));
+ }
+ }
}

File Metadata

Mime Type
text/plain
Expires
Sun, Mar 16, 2:24 AM (3 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7690072
Default Alt Text
D17440.id.diff (5 KB)

Event Timeline