diff --git a/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditField.php b/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditField.php index 1153f82a34..27b8276c85 100644 --- a/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditField.php +++ b/src/infrastructure/customfield/editor/PhabricatorCustomFieldEditField.php @@ -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(); diff --git a/src/infrastructure/customfield/field/PhabricatorCustomField.php b/src/infrastructure/customfield/field/PhabricatorCustomField.php index 818bf119ff..36db8f239b 100644 --- a/src/infrastructure/customfield/field/PhabricatorCustomField.php +++ b/src/infrastructure/customfield/field/PhabricatorCustomField.php @@ -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 )------------------------------------------------------------- */ diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldTokenizer.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldTokenizer.php index 9bf59d41f6..3c5268d65b 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldTokenizer.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldTokenizer.php @@ -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; + } + }