Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / ponder / controller / PonderAnswerEditController.php
blob9c48c7c669e91a84656b911b720afd295686f7e7
1 <?php
3 final class PonderAnswerEditController extends PonderController {
5 public function handleRequest(AphrontRequest $request) {
6 $viewer = $request->getViewer();
7 $id = $request->getURIData('id');
9 $answer = id(new PonderAnswerQuery())
10 ->setViewer($viewer)
11 ->withIDs(array($id))
12 ->requireCapabilities(
13 array(
14 PhabricatorPolicyCapability::CAN_VIEW,
15 PhabricatorPolicyCapability::CAN_EDIT,
17 ->executeOne();
18 if (!$answer) {
19 return new Aphront404Response();
22 $v_content = $answer->getContent();
23 $v_status = $answer->getStatus();
24 $e_content = true;
27 $question = $answer->getQuestion();
28 $qid = $question->getID();
30 $answer_uri = $answer->getURI();
32 $errors = array();
33 if ($request->isFormPost()) {
34 $v_content = $request->getStr('content');
35 $v_status = $request->getStr('status');
37 if (!strlen($v_content)) {
38 $errors[] = pht('You must provide some substance in your answer.');
39 $e_content = pht('Required');
42 if (!$errors) {
43 $xactions = array();
44 $xactions[] = id(new PonderAnswerTransaction())
45 ->setTransactionType(PonderAnswerContentTransaction::TRANSACTIONTYPE)
46 ->setNewValue($v_content);
48 $xactions[] = id(new PonderAnswerTransaction())
49 ->setTransactionType(PonderAnswerStatusTransaction::TRANSACTIONTYPE)
50 ->setNewValue($v_status);
52 $editor = id(new PonderAnswerEditor())
53 ->setActor($viewer)
54 ->setContentSourceFromRequest($request)
55 ->setContinueOnNoEffect(true);
57 $editor->applyTransactions($answer, $xactions);
59 return id(new AphrontRedirectResponse())
60 ->setURI($answer_uri);
64 $answer_content_id = celerity_generate_unique_node_id();
66 $form = id(new AphrontFormView())
67 ->setUser($viewer)
68 ->appendChild(
69 id(new AphrontFormStaticControl())
70 ->setLabel(pht('Question'))
71 ->setValue($question->getTitle()))
72 ->appendChild(
73 id(new AphrontFormSelectControl())
74 ->setLabel(pht('Status'))
75 ->setName('status')
76 ->setValue($v_status)
77 ->setOptions(PonderAnswerStatus::getAnswerStatusMap()))
78 ->appendChild(
79 id(new PhabricatorRemarkupControl())
80 ->setUser($viewer)
81 ->setLabel(pht('Answer'))
82 ->setName('content')
83 ->setID($answer_content_id)
84 ->setValue($v_content)
85 ->setError($e_content))
86 ->appendChild(
87 id(new AphrontFormSubmitControl())
88 ->setValue(pht('Submit'))
89 ->addCancelButton($answer_uri));
91 $crumbs = $this->buildApplicationCrumbs();
92 $crumbs->addTextCrumb("Q{$qid}", $answer_uri);
93 $crumbs->addTextCrumb(pht('Edit Answer'));
94 $crumbs->setBorder(true);
96 $header = id(new PHUIHeaderView())
97 ->setHeader(pht('Edit Answer'))
98 ->setHeaderIcon('fa-pencil');
100 $box = id(new PHUIObjectBoxView())
101 ->setHeaderText(pht('Answer'))
102 ->setFormErrors($errors)
103 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
104 ->setForm($form);
106 $preview = id(new PHUIRemarkupPreviewPanel())
107 ->setHeader(pht('Answer Preview'))
108 ->setControlID($answer_content_id)
109 ->setPreviewURI($this->getApplicationURI('preview/'));
111 $view = id(new PHUITwoColumnView())
112 ->setHeader($header)
113 ->setFooter(array(
114 $box,
115 $preview,
118 return $this->newPage()
119 ->setTitle(pht('Edit Answer'))
120 ->setCrumbs($crumbs)
121 ->appendChild($view);