diff --git a/src/applications/maniphest/editor/ManiphestEditEngine.php b/src/applications/maniphest/editor/ManiphestEditEngine.php --- a/src/applications/maniphest/editor/ManiphestEditEngine.php +++ b/src/applications/maniphest/editor/ManiphestEditEngine.php @@ -69,6 +69,14 @@ return pht('Set Sail for Adventure'); } + public function getCommentFieldPlaceholderText($object) { + if ($object->getStatus() === ManiphestTaskStatus::STATUS_CLOSED_DUPLICATE) { + return pht('This task is closed as a duplicate. '. + 'Only comment if you think that this task is not a duplicate.'); + } + return ''; + } + protected function getObjectViewURI($object) { return '/'.$object->getMonogram(); } diff --git a/src/applications/pholio/controller/PholioMockViewController.php b/src/applications/pholio/controller/PholioMockViewController.php --- a/src/applications/pholio/controller/PholioMockViewController.php +++ b/src/applications/pholio/controller/PholioMockViewController.php @@ -223,7 +223,7 @@ $form = id(new PhabricatorApplicationTransactionCommentView()) ->setUser($viewer) - ->setObjectPHID($mock->getPHID()) + ->setObject($mock) ->setFormID($comment_form_id) ->setDraft($draft) ->setHeaderText($title) diff --git a/src/applications/ponder/controller/PonderQuestionViewController.php b/src/applications/ponder/controller/PonderQuestionViewController.php --- a/src/applications/ponder/controller/PonderQuestionViewController.php +++ b/src/applications/ponder/controller/PonderQuestionViewController.php @@ -60,7 +60,7 @@ $add_comment = id(new PhabricatorApplicationTransactionCommentView()) ->setUser($viewer) - ->setObjectPHID($question->getPHID()) + ->setObject($question) ->setShowPreview(false) ->setAction($this->getApplicationURI("/question/comment/{$id}/")) ->setSubmitButtonName(pht('Comment')); diff --git a/src/applications/ponder/view/PonderAnswerView.php b/src/applications/ponder/view/PonderAnswerView.php --- a/src/applications/ponder/view/PonderAnswerView.php +++ b/src/applications/ponder/view/PonderAnswerView.php @@ -121,7 +121,7 @@ $comment_view = id(new PhabricatorApplicationTransactionCommentView()) ->setUser($viewer) - ->setObjectPHID($answer->getPHID()) + ->setObject($answer) ->setShowPreview(false) ->setHeaderText(pht('Answer Comment')) ->setAction("/ponder/answer/comment/{$id}/") diff --git a/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php b/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php --- a/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php +++ b/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php @@ -154,7 +154,7 @@ return id(new PhabricatorApplicationTransactionCommentView()) ->setUser($viewer) - ->setObjectPHID($poll->getPHID()) + ->setObject($poll) ->setDraft($draft) ->setHeaderText($add_comment_header) ->setAction($this->getApplicationURI('/comment/'.$poll->getID().'/')) diff --git a/src/applications/transactions/editengine/PhabricatorEditEngine.php b/src/applications/transactions/editengine/PhabricatorEditEngine.php --- a/src/applications/transactions/editengine/PhabricatorEditEngine.php +++ b/src/applications/transactions/editengine/PhabricatorEditEngine.php @@ -339,7 +339,17 @@ return null; } - + /** + * Set default placeholder plain text in the comment textarea of the engine. + * To be overwritten by conditions defined in the child EditEngine class. + * + * @param object Object in which the comment textarea is displayed. + * @return string Placeholder text to display in the comment textarea. + * @task text + */ + public function getCommentFieldPlaceholderText($object) { + return ''; + } /** * Return a human-readable header describing what this engine is used to do, @@ -1668,6 +1678,8 @@ ->setHeaderText($header_text) ->setAction($comment_uri) ->setRequiresMFA($requires_mfa) + ->setObject($object) + ->setEditEngine($this) ->setSubmitButtonName($button_text); $draft = PhabricatorVersionedDraft::loadDraft( diff --git a/src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php b/src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php --- a/src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php +++ b/src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php @@ -15,11 +15,13 @@ private $draft; private $requestURI; private $showPreview = true; + private $object; private $objectPHID; private $headerText; private $noPermission; private $fullWidth; private $infoView; + private $editEngine; private $editEngineLock; private $noBorder; private $requiresMFA; @@ -30,13 +32,19 @@ private $commentActionGroups = array(); private $transactionTimeline; - public function setObjectPHID($object_phid) { - $this->objectPHID = $object_phid; + /** + * Set object in which this comment textarea field is displayed + */ + public function setObject($object) { + $this->object = $object; return $this; } - public function getObjectPHID() { - return $this->objectPHID; + /** + * Get object in which this comment textarea is displayed + */ + public function getObject() { + return $this->object; } public function setShowPreview($show_preview) { @@ -150,6 +158,15 @@ return $this->noPermission; } + public function setEditEngine(PhabricatorEditEngine $edit_engine) { + $this->editEngine = $edit_engine; + return $this; + } + + public function getEditEngine() { + return $this->editEngine; + } + public function setEditEngineLock(PhabricatorEditEngineLock $lock) { $this->editEngineLock = $lock; return $this; @@ -295,6 +312,15 @@ private function renderCommentPanel() { $viewer = $this->getViewer(); + $engine = $this->getEditEngine(); + // In a few rare cases PhabricatorApplicationTransactionCommentView gets + // initiated in a View or Controller class. Don't crash in that case. + if ($engine) { + $placeholder_text = $engine + ->getCommentFieldPlaceholderText($this->getObject()); + } else { + $placeholder_text = ''; + } $remarkup_control = id(new PhabricatorRemarkupControl()) ->setViewer($viewer) @@ -302,6 +328,7 @@ ->addClass('phui-comment-fullwidth-control') ->addClass('phui-comment-textarea-control') ->setCanPin(true) + ->setPlaceholder($placeholder_text) ->setName('comment'); $draft_comment = ''; @@ -331,7 +358,7 @@ } $remarkup_control->setRemarkupMetadata($draft_metadata); - if (!$this->getObjectPHID()) { + if (!$this->getObject()->getPHID()) { throw new PhutilInvalidStateException('setObjectPHID', 'render'); } @@ -345,7 +372,7 @@ ->setFullWidth($this->fullWidth) ->setMetadata( array( - 'objectPHID' => $this->getObjectPHID(), + 'objectPHID' => $this->getObject()->getPHID(), )) ->setAction($this->getAction()) ->setID($this->getFormID())