Commit bbc9a7d7 authored by Daniel Stone's avatar Daniel Stone Committed by Ana Rute Mendes
Browse files

WIP: Maniphest: Allow restricting custom fields to subtypes

Add a 'subtype' parameter to custom fields, which means they will only
be visible on (and validated with) tasks of a particular subtype.

Suitable for upstream after much rework:
https://secure.phabricator.com/D17593
parent 745775ca
...@@ -545,5 +545,20 @@ EODOCS ...@@ -545,5 +545,20 @@ EODOCS
return $map; return $map;
} }
protected function willConfigureFields($object, array $fields) {
$subtype = $this->getEditEngineConfiguration()->getSubType();
if ($subtype) {
foreach ($fields as $key => $field) {
if ($field instanceof PhabricatorCustomFieldEditField) {
$subtypes = $field->getCustomField()->getFieldConfigValue('subtypes');
if ($subtypes && !in_array($subtype, $subtypes)) {
unset($fields[$key]);
}
}
}
}
return $fields;
}
} }
...@@ -2629,6 +2629,18 @@ abstract class PhabricatorApplicationTransactionEditor ...@@ -2629,6 +2629,18 @@ abstract class PhabricatorApplicationTransactionEditor
$object, $object,
$xactions, $xactions,
$type); $type);
/* XXX: This is nasty. We can't otherwise validate that a given field
* is appropriate for the subtype, because we don't have access
* to the EditEngine's configuration, if it even has one.
* Ideally we should do this in two passes, where we sweep all
* the transactions looking for a subtype, set it on the
* TransactionEditor, and can then access that from validation. */
if ($this->getIsNewObject() && !empty($xactions)) {
foreach ($xactions as $xaction) {
$object->setEditEngineSubtype($xaction->getNewValue());
}
}
break; break;
case PhabricatorTransactions::TYPE_MFA: case PhabricatorTransactions::TYPE_MFA:
$errors[] = $this->validateMFATransactions( $errors[] = $this->validateMFATransactions(
......
...@@ -359,6 +359,17 @@ abstract class PhabricatorStandardCustomField ...@@ -359,6 +359,17 @@ abstract class PhabricatorStandardCustomField
$type, $type,
$xactions); $xactions);
$object = $this->getObject();
if ($object instanceof PhabricatorEditEngineSubtypeInterface) {
$subtype = $object->getEditEngineSubtype();
if ($subtype) {
$subtypes = $this->getFieldConfigValue('subtypes');
if ($subtypes && !in_array($subtype, $subtypes)) {
return $errors;
}
}
}
if ($this->getRequired()) { if ($this->getRequired()) {
$value = $this->getOldValueForApplicationTransactions(); $value = $this->getOldValueForApplicationTransactions();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment