Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / flag / controller / PhabricatorFlagEditController.php
blob5844a3801a533952e1c3a35201a17904865f4a96
1 <?php
3 final class PhabricatorFlagEditController extends PhabricatorFlagController {
5 public function handleRequest(AphrontRequest $request) {
6 $viewer = $request->getViewer();
7 $phid = $request->getURIData('phid');
9 $handle = id(new PhabricatorHandleQuery())
10 ->setViewer($viewer)
11 ->withPHIDs(array($phid))
12 ->executeOne();
14 if (!$handle->isComplete()) {
15 return new Aphront404Response();
18 $flag = PhabricatorFlagQuery::loadUserFlag($viewer, $phid);
20 if (!$flag) {
21 $flag = new PhabricatorFlag();
22 $flag->setOwnerPHID($viewer->getPHID());
23 $flag->setType($handle->getType());
24 $flag->setObjectPHID($handle->getPHID());
25 $flag->setReasonPHID($viewer->getPHID());
28 if ($request->isDialogFormPost()) {
29 $flag->setColor($request->getInt('color'));
30 $flag->setNote($request->getStr('note'));
31 $flag->save();
33 return id(new AphrontReloadResponse())->setURI('/flag/');
36 $type_name = $handle->getTypeName();
38 $dialog = new AphrontDialogView();
39 $dialog->setUser($viewer);
41 $dialog->setTitle(pht('Flag %s', $type_name));
43 require_celerity_resource('phabricator-flag-css');
45 $form = new PHUIFormLayoutView();
47 $is_new = !$flag->getID();
49 if ($is_new) {
50 $form
51 ->appendChild(hsprintf(
52 '<p>%s</p><br />',
53 pht('You can flag this %s if you want to remember to look '.
54 'at it later.',
55 $type_name)));
58 $radio = new AphrontFormRadioButtonControl();
59 foreach (PhabricatorFlagColor::getColorNameMap() as $color => $text) {
60 $class = 'phabricator-flag-radio phabricator-flag-color-'.$color;
61 $radio->addButton($color, $text, '', $class);
64 $form
65 ->appendChild(
66 $radio
67 ->setName('color')
68 ->setLabel(pht('Flag Color'))
69 ->setValue($flag->getColor()))
70 ->appendChild(
71 id(new AphrontFormTextAreaControl())
72 ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)
73 ->setName('note')
74 ->setLabel(pht('Note'))
75 ->setValue($flag->getNote()));
77 $dialog->appendChild($form);
79 $dialog->addCancelButton($handle->getURI());
80 $dialog->addSubmitButton(
81 $is_new ? pht('Create Flag') : pht('Save'));
83 return id(new AphrontDialogResponse())->setDialog($dialog);