1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 18:22:41 +01:00

Provide comment actions for tokenizer custom fields

Summary:
Ref T13114. See PHI519. An install is interested in modifying a tokenizer custom field from the comment area. Provide this capability.

This patch is fairly narrow but should solve the immediate need.

Test Plan: Added, removed, and modified a tokenizer custom field using the comment action dropdown.

Maniphest Tasks: T13114

Differential Revision: https://secure.phabricator.com/D19270
This commit is contained in:
epriestley 2018-03-29 14:03:48 -07:00
parent 7f9a9bc800
commit 9fbf4ee58c
3 changed files with 77 additions and 0 deletions

View file

@ -7,6 +7,7 @@ final class PhabricatorCustomFieldEditField
private $httpParameterType;
private $conduitParameterType;
private $bulkParameterType;
private $commentAction;
public function setCustomField(PhabricatorCustomField $custom_field) {
$this->customField = $custom_field;
@ -47,6 +48,16 @@ final class PhabricatorCustomFieldEditField
return $this->bulkParameterType;
}
public function setCustomFieldCommentAction(
PhabricatorEditEngineCommentAction $comment_action) {
$this->commentAction = $comment_action;
return $this;
}
public function getCustomFieldCommentAction() {
return $this->commentAction;
}
protected function buildControl() {
if ($this->getIsConduitOnly()) {
return null;
@ -77,6 +88,19 @@ final class PhabricatorCustomFieldEditField
return $clone->getNewValueForApplicationTransactions();
}
protected function getValueForCommentAction($value) {
$field = $this->getCustomField();
$clone = clone $field;
$clone->setValueFromApplicationTransactions($value);
// TODO: This is somewhat bogus because only StandardCustomFields
// implement a getFieldValue() method -- not all CustomFields. Today,
// only StandardCustomFields can ever actually generate a comment action
// so we never reach this method with other field types.
return $clone->getFieldValue();
}
protected function getValueExistsInSubmit(AphrontRequest $request, $key) {
return true;
}
@ -110,6 +134,16 @@ final class PhabricatorCustomFieldEditField
return null;
}
protected function newCommentAction() {
$action = $this->getCustomFieldCommentAction();
if ($action) {
return clone $action;
}
return null;
}
protected function newConduitParameterType() {
$type = $this->getCustomFieldConduitParameterType();

View file

@ -1127,6 +1127,16 @@ abstract class PhabricatorCustomField extends Phobject {
$field->setCustomFieldBulkParameterType($bulk_type);
}
$comment_action = $this->getCommentAction();
if ($comment_action) {
$field
->setCustomFieldCommentAction($comment_action)
->setCommentActionLabel(
pht(
'Change %s',
$this->getFieldName()));
}
return $field;
}
@ -1459,6 +1469,17 @@ abstract class PhabricatorCustomField extends Phobject {
return null;
}
public function getCommentAction() {
return $this->newCommentAction();
}
protected function newCommentAction() {
if ($this->proxy) {
return $this->proxy->newCommentAction();
}
return null;
}
/* -( Herald )------------------------------------------------------------- */

View file

@ -143,4 +143,26 @@ abstract class PhabricatorStandardCustomFieldTokenizer
->setDatasource($datasource);
}
protected function newCommentAction() {
$viewer = $this->getViewer();
$datasource = $this->getDatasource()
->setViewer($viewer);
$action = id(new PhabricatorEditEngineTokenizerCommentAction())
->setDatasource($datasource);
$limit = $this->getFieldConfigValue('limit');
if ($limit) {
$action->setLimit($limit);
}
$value = $this->getFieldValue();
if ($value !== null) {
$action->setInitialValue($value);
}
return $action;
}
}