mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 06:20:56 +01:00
Support comments as an EditEngine field
Summary: Ref T9132. This adds an automatic "Comments" field, like the Subscribers/Projects/Policy fields. The primary goals here are: - Allow users to make comments via Conduit. - In the future, get stackable action support. As a side effect, this also allows you to put comments on create forms. This is a little silly but seems fine, and may be relevant on edit forms (which I'm not 100% sure how I want to handle yet). I've just hidden them by default for now. Test Plan: {F976036} {F976037} {F976038} Reviewers: chad Reviewed By: chad Maniphest Tasks: T9132 Differential Revision: https://secure.phabricator.com/D14515
This commit is contained in:
parent
269e0bfc94
commit
c034752578
9 changed files with 102 additions and 3 deletions
|
@ -1843,6 +1843,8 @@ phutil_register_library_map(array(
|
|||
'PhabricatorChatLogQuery' => 'applications/chatlog/query/PhabricatorChatLogQuery.php',
|
||||
'PhabricatorChunkedFileStorageEngine' => 'applications/files/engine/PhabricatorChunkedFileStorageEngine.php',
|
||||
'PhabricatorClusterConfigOptions' => 'applications/config/option/PhabricatorClusterConfigOptions.php',
|
||||
'PhabricatorCommentEditField' => 'applications/transactions/editfield/PhabricatorCommentEditField.php',
|
||||
'PhabricatorCommentEditType' => 'applications/transactions/edittype/PhabricatorCommentEditType.php',
|
||||
'PhabricatorCommitBranchesField' => 'applications/repository/customfield/PhabricatorCommitBranchesField.php',
|
||||
'PhabricatorCommitCustomField' => 'applications/repository/customfield/PhabricatorCommitCustomField.php',
|
||||
'PhabricatorCommitMergedCommitsField' => 'applications/repository/customfield/PhabricatorCommitMergedCommitsField.php',
|
||||
|
@ -5890,6 +5892,8 @@ phutil_register_library_map(array(
|
|||
'PhabricatorChatLogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorChunkedFileStorageEngine' => 'PhabricatorFileStorageEngine',
|
||||
'PhabricatorClusterConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||
'PhabricatorCommentEditField' => 'PhabricatorEditField',
|
||||
'PhabricatorCommentEditType' => 'PhabricatorEditType',
|
||||
'PhabricatorCommitBranchesField' => 'PhabricatorCommitCustomField',
|
||||
'PhabricatorCommitCustomField' => 'PhabricatorCustomField',
|
||||
'PhabricatorCommitMergedCommitsField' => 'PhabricatorCommitCustomField',
|
||||
|
|
|
@ -90,11 +90,19 @@ EOTEXT
|
|||
$label = $key;
|
||||
}
|
||||
|
||||
if ($field->getIsHidden()) {
|
||||
$value = $lock_hidden;
|
||||
} else if ($field->getIsLocked()) {
|
||||
$value = $lock_locked;
|
||||
} else {
|
||||
$value = $lock_visible;
|
||||
}
|
||||
|
||||
$form->appendControl(
|
||||
id(new AphrontFormSelectControl())
|
||||
->setName('locks['.$key.']')
|
||||
->setLabel($label)
|
||||
->setValue(idx($locks, $key, $lock_visible))
|
||||
->setValue($value)
|
||||
->setOptions($map));
|
||||
}
|
||||
|
||||
|
|
|
@ -214,6 +214,22 @@ abstract class PhabricatorEditEngine
|
|||
}
|
||||
}
|
||||
|
||||
$xaction = $object->getApplicationTransactionTemplate();
|
||||
$comment = $xaction->getApplicationTransactionCommentObject();
|
||||
if ($comment) {
|
||||
$comment_type = PhabricatorTransactions::TYPE_COMMENT;
|
||||
|
||||
$comment_field = id(new PhabricatorCommentEditField())
|
||||
->setKey('comment')
|
||||
->setLabel(pht('Comments'))
|
||||
->setDescription(pht('Add comments.'))
|
||||
->setAliases(array('comments'))
|
||||
->setIsHidden(true)
|
||||
->setTransactionType($comment_type)
|
||||
->setValue(null);
|
||||
$fields[] = $comment_field;
|
||||
}
|
||||
|
||||
$config = $this->getEditEngineConfiguration();
|
||||
$fields = $config->applyConfigurationToFields($this, $fields);
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorCommentEditField
|
||||
extends PhabricatorEditField {
|
||||
|
||||
protected function newControl() {
|
||||
return new PhabricatorRemarkupControl();
|
||||
}
|
||||
|
||||
protected function newEditType() {
|
||||
return new PhabricatorCommentEditType();
|
||||
}
|
||||
|
||||
public function generateTransaction(
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
$spec = array(
|
||||
'value' => $this->getValueForTransaction(),
|
||||
);
|
||||
|
||||
return head($this->getEditTransactionTypes())
|
||||
->generateTransaction($xaction, $spec);
|
||||
}
|
||||
|
||||
}
|
|
@ -357,6 +357,11 @@ abstract class PhabricatorEditField extends Phobject {
|
|||
return $this->editTypeKey;
|
||||
}
|
||||
|
||||
protected function newEditType() {
|
||||
return id(new PhabricatorSimpleEditType())
|
||||
->setValueType($this->getHTTPParameterType()->getTypeName());
|
||||
}
|
||||
|
||||
public function getEditTransactionTypes() {
|
||||
$transaction_type = $this->getTransactionType();
|
||||
if ($transaction_type === null) {
|
||||
|
@ -411,10 +416,9 @@ abstract class PhabricatorEditField extends Phobject {
|
|||
}
|
||||
|
||||
return array(
|
||||
id(new PhabricatorSimpleEditType())
|
||||
$this->newEditType()
|
||||
->setEditType($type_key)
|
||||
->setTransactionType($transaction_type)
|
||||
->setValueType($this->getHTTPParameterType()->getTypeName())
|
||||
->setDescription($this->getDescription())
|
||||
->setMetadata($this->metadata),
|
||||
);
|
||||
|
|
|
@ -7,4 +7,8 @@ final class PhabricatorInstructionsEditField
|
|||
return $form->appendRemarkupInstructions($this->getValue());
|
||||
}
|
||||
|
||||
protected function newHTTPParameterType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorCommentEditType extends PhabricatorEditType {
|
||||
|
||||
public function getValueType() {
|
||||
return id(new AphrontStringHTTPParameterType())->getTypeName();
|
||||
}
|
||||
|
||||
public function generateTransaction(
|
||||
PhabricatorApplicationTransaction $template,
|
||||
array $spec) {
|
||||
|
||||
$comment = $template->getApplicationTransactionCommentObject()
|
||||
->setContent(idx($spec, 'value'));
|
||||
|
||||
$template
|
||||
->setTransactionType($this->getTransactionType())
|
||||
->attachComment($comment);
|
||||
|
||||
foreach ($this->getMetadata() as $key => $value) {
|
||||
$template->setMetadataValue($key, $value);
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
public function getValueDescription() {
|
||||
return pht('Comment to add, formated as remarkup.');
|
||||
}
|
||||
|
||||
}
|
|
@ -106,13 +106,19 @@ final class PhabricatorEditEngineConfiguration
|
|||
$key = $field->getKey();
|
||||
switch (idx($locks, $key)) {
|
||||
case self::LOCK_LOCKED:
|
||||
$field->setIsHidden(false);
|
||||
$field->setIsLocked(true);
|
||||
break;
|
||||
case self::LOCK_HIDDEN:
|
||||
$field->setIsHidden(true);
|
||||
$field->setIsLocked(false);
|
||||
break;
|
||||
case self::LOCK_VISIBLE:
|
||||
$field->setIsHidden(false);
|
||||
$field->setIsLocked(false);
|
||||
break;
|
||||
default:
|
||||
// If we don't have an explicit value, don't make any adjustments.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ final class PhabricatorApplicationEditHTTPParameterHelpView
|
|||
$type = $field->getHTTPParameterType();
|
||||
if ($type === null) {
|
||||
unset($fields[$key]);
|
||||
continue;
|
||||
}
|
||||
$types[$type->getTypeName()] = $type;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue