@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 ManiphestTaskSubtaskController
4 extends ManiphestController {
5
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $this->getViewer();
8 $id = $request->getURIData('id');
9
10 $task = id(new ManiphestTaskQuery())
11 ->setViewer($viewer)
12 ->withIDs(array($id))
13 ->executeOne();
14 if (!$task) {
15 return new Aphront404Response();
16 }
17
18 $cancel_uri = $task->getURI();
19
20 $edit_engine = id(new ManiphestEditEngine())
21 ->setViewer($viewer)
22 ->setTargetObject($task);
23
24 $subtype_map = $task->newEditEngineSubtypeMap();
25
26 $subtype_options = $subtype_map->getCreateFormsForSubtype(
27 $edit_engine,
28 $task);
29
30 if (!$subtype_options) {
31 return $this->newDialog()
32 ->setTitle(pht('No Forms'))
33 ->appendParagraph(
34 pht(
35 'You do not have access to any forms which can be used to '.
36 'create a subtask.'))
37 ->addCancelButton($cancel_uri, pht('Close'));
38 }
39
40 $menu = id(new PHUIObjectItemListView())
41 ->setUser($viewer)
42 ->setBig(true)
43 ->setFlush(true);
44
45 foreach ($subtype_options as $form_key => $subtype_form) {
46 $subtype_key = $subtype_form->getSubtype();
47 $subtype = $subtype_map->getSubtype($subtype_key);
48
49 $subtask_uri = id(new PhutilURI("/task/edit/form/{$form_key}/"))
50 ->replaceQueryParam('parent', $id)
51 ->replaceQueryParam('template', $id)
52 ->replaceQueryParam('status', ManiphestTaskStatus::getDefaultStatus());
53 $subtask_uri = $this->getApplicationURI($subtask_uri);
54
55 $item = id(new PHUIObjectItemView())
56 ->setHeader($subtype_form->getDisplayName())
57 ->setHref($subtask_uri)
58 ->setClickable(true)
59 ->setImageIcon($subtype->newIconView())
60 ->addAttribute($subtype->getName());
61
62 $menu->addItem($item);
63 }
64
65 return $this->newDialog()
66 ->setTitle(pht('Choose Subtype'))
67 ->appendChild($menu)
68 ->addCancelButton($cancel_uri);
69 }
70
71}