diff --git a/src/applications/maniphest/auxiliaryfield/base/ManiphestAuxiliaryFieldSpecification.php b/src/applications/maniphest/auxiliaryfield/base/ManiphestAuxiliaryFieldSpecification.php index 92a119b149..798f7ac5c1 100644 --- a/src/applications/maniphest/auxiliaryfield/base/ManiphestAuxiliaryFieldSpecification.php +++ b/src/applications/maniphest/auxiliaryfield/base/ManiphestAuxiliaryFieldSpecification.php @@ -91,6 +91,20 @@ abstract class ManiphestAuxiliaryFieldSpecification { } + /** + * When the user creates a task, the UI prompts them to "Create another + * similar task". This copies some fields (e.g., Owner and CCs) but not other + * fields (e.g., description). If this custom field should also be copied, + * return true from this method. + * + * @return bool True to copy the default value from the template task when + * creating a new similar task. + */ + public function shouldCopyWhenCreatingSimilarTask() { + return false; + } + + /** * Render a verb to appear in email titles when a transaction involving this * field occurs. Specifically, Maniphest emails are formatted like this: diff --git a/src/applications/maniphest/auxiliaryfield/default/ManiphestAuxiliaryFieldDefaultSpecification.php b/src/applications/maniphest/auxiliaryfield/default/ManiphestAuxiliaryFieldDefaultSpecification.php index 658fd1f6d3..faa341effd 100644 --- a/src/applications/maniphest/auxiliaryfield/default/ManiphestAuxiliaryFieldDefaultSpecification.php +++ b/src/applications/maniphest/auxiliaryfield/default/ManiphestAuxiliaryFieldDefaultSpecification.php @@ -29,6 +29,7 @@ class ManiphestAuxiliaryFieldDefaultSpecification private $checkboxLabel; private $checkboxValue; private $error; + private $shouldCopyWhenCreatingSimilarTask; const TYPE_SELECT = 'select'; const TYPE_STRING = 'string'; @@ -178,6 +179,7 @@ class ManiphestAuxiliaryFieldDefaultSpecification return parent::renderForDetailView(); } + public function renderTransactionDescription( ManiphestTransaction $transaction, $target) { @@ -224,4 +226,13 @@ class ManiphestAuxiliaryFieldDefaultSpecification return $desc; } + public function setShouldCopyWhenCreatingSimilarTask($copy) { + $this->shouldCopyWhenCreatingSimilarTask = $copy; + return $this; + } + + public function shouldCopyWhenCreatingSimilarTask() { + return $this->shouldCopyWhenCreatingSimilarTask; + } + } diff --git a/src/applications/maniphest/controller/taskedit/ManiphestTaskEditController.php b/src/applications/maniphest/controller/taskedit/ManiphestTaskEditController.php index 44b1cd84c8..fbbb31d14f 100644 --- a/src/applications/maniphest/controller/taskedit/ManiphestTaskEditController.php +++ b/src/applications/maniphest/controller/taskedit/ManiphestTaskEditController.php @@ -277,6 +277,15 @@ final class ManiphestTaskEditController extends ManiphestController { ->setURI($redirect_uri); } } else { + if ($aux_fields) { + $task->loadAndAttachAuxiliaryAttributes(); + foreach ($aux_fields as $aux_field) { + $aux_key = $aux_field->getAuxiliaryKey(); + $value = $task->getAuxiliaryAttribute($aux_key); + $aux_field->setValueFromStorage($value); + } + } + if (!$task->getID()) { $task->setCCPHIDs(array( $user->getPHID(), @@ -287,6 +296,19 @@ final class ManiphestTaskEditController extends ManiphestController { $task->setCCPHIDs($template_task->getCCPHIDs()); $task->setProjectPHIDs($template_task->getProjectPHIDs()); $task->setOwnerPHID($template_task->getOwnerPHID()); + + if ($aux_fields) { + $template_task->loadAndAttachAuxiliaryAttributes(); + foreach ($aux_fields as $aux_field) { + if (!$aux_field->shouldCopyWhenCreatingSimilarTask()) { + continue; + } + + $aux_key = $aux_field->getAuxiliaryKey(); + $value = $template_task->getAuxiliaryAttribute($aux_key); + $aux_field->setValueFromStorage($value); + } + } } } } @@ -438,16 +460,6 @@ final class ManiphestTaskEditController extends ManiphestController { ->setDatasource('/typeahead/common/projects/')); if ($aux_fields) { - - if (!$request->isFormPost()) { - $task->loadAndAttachAuxiliaryAttributes(); - foreach ($aux_fields as $aux_field) { - $aux_key = $aux_field->getAuxiliaryKey(); - $value = $task->getAuxiliaryAttribute($aux_key); - $aux_field->setValueFromStorage($value); - } - } - foreach ($aux_fields as $aux_field) { if ($aux_field->isRequired() && !$aux_field->getError() && diff --git a/src/applications/maniphest/extensions/task/ManiphestDefaultTaskExtensions.php b/src/applications/maniphest/extensions/task/ManiphestDefaultTaskExtensions.php index 1ee4d049b9..d6f099f3bb 100644 --- a/src/applications/maniphest/extensions/task/ManiphestDefaultTaskExtensions.php +++ b/src/applications/maniphest/extensions/task/ManiphestDefaultTaskExtensions.php @@ -1,7 +1,7 @@ setSelectOptions(idx($info, 'options')); } + $spec->setShouldCopyWhenCreatingSimilarTask(idx($info, 'copy')); $specs[] = $spec; } diff --git a/src/docs/userguide/maniphest_custom.diviner b/src/docs/userguide/maniphest_custom.diviner index 2f433a2e9a..80e55700c6 100644 --- a/src/docs/userguide/maniphest_custom.diviner +++ b/src/docs/userguide/maniphest_custom.diviner @@ -53,6 +53,10 @@ the field. These options are available: show next to the checkbox. - **checkbox-value**: If type is set to **bool**, the value to show on the detail view when the checkbox is selected. + - **copy**: When a user creates a task, the UI gives them an option to + "Create Another Similar Task". Some fields from the original task are copied + into the new task, while others are not; by default, fields are not copied. + If you want this field to be copied, specify `true` for the `copy` property. = Advanced Field Customization = @@ -63,7 +67,7 @@ rendering logic, you can do so with a little work: your specialized rendering, validation, storage, etc., logic. - Extend @{class:ManiphestTaskExtensions} and return a list of fields which includes your custom field objects. - - Set 'maniphest.custom-extensions' to the name of your new extensions + - Set `maniphest.custom-extensions` to the name of your new extensions class. This is relatively advanced but should give you significant flexibility in