@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PonderAddAnswerView extends AphrontView {
4
5 private $question;
6 private $actionURI;
7 private $draft;
8
9 public function setQuestion($question) {
10 $this->question = $question;
11 return $this;
12 }
13
14 public function setActionURI($uri) {
15 $this->actionURI = $uri;
16 return $this;
17 }
18
19 public function render() {
20 $question = $this->question;
21 $viewer = $this->getViewer();
22
23 $authors = mpull($question->getAnswers(), null, 'getAuthorPHID');
24 if (isset($authors[$viewer->getPHID()])) {
25 $view = id(new PHUIInfoView())
26 ->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
27 ->setTitle(pht('Already Answered'))
28 ->appendChild(
29 pht(
30 'You have already answered this question. You can not answer '.
31 'twice, but you can edit your existing answer.'));
32 return phutil_tag_div('ponder-add-answer-view', $view);
33 }
34
35 $info_panel = null;
36 if ($question->getStatus() != PonderQuestionStatus::STATUS_OPEN) {
37 $info_panel = id(new PHUIInfoView())
38 ->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
39 ->appendChild(
40 pht(
41 'This question has been marked as closed,
42 but you can still leave a new answer.'));
43 }
44
45 $box_style = null;
46 $header = id(new PHUIHeaderView())
47 ->setHeader(pht('New Answer'))
48 ->addClass('ponder-add-answer-header');
49
50 $form = new AphrontFormView();
51 $form
52 ->setViewer($viewer)
53 ->setAction($this->actionURI)
54 ->setWorkflow(true)
55 ->addHiddenInput('question_id', $question->getID())
56 ->appendChild(
57 id(new PhabricatorRemarkupControl())
58 ->setName('answer')
59 ->setLabel(pht('Answer'))
60 ->setError(true)
61 ->setID('answer-content')
62 ->setViewer($viewer))
63 ->appendChild(
64 id(new AphrontFormSubmitControl())
65 ->setValue(pht('Add Answer')));
66
67 if (!$viewer->isLoggedIn()) {
68 $login_href = id(new PhutilURI('/auth/start/'))
69 ->replaceQueryParam('next', '/Q'.$question->getID());
70 $form = id(new PHUIFormLayoutView())
71 ->addClass('login-to-participate')
72 ->appendChild(
73 id(new PHUIButtonView())
74 ->setTag('a')
75 ->setText(pht('Log In to Answer'))
76 ->setHref((string)$login_href));
77 }
78
79 $box = id(new PHUIObjectBoxView())
80 ->appendChild($form)
81 ->setHeaderText(pht('Answer'))
82 ->addClass('ponder-add-answer-view');
83
84 if ($info_panel) {
85 $box->setInfoView($info_panel);
86 }
87
88 return array($header, $box);
89 }
90}