@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 SubscriptionListDialogBuilder extends Phobject {
4
5 private $viewer;
6 private $handles;
7 private $objectPHID;
8 private $title;
9
10 public function setViewer(PhabricatorUser $viewer) {
11 $this->viewer = $viewer;
12 return $this;
13 }
14
15 public function getViewer() {
16 return $this->viewer;
17 }
18
19 /**
20 * @param array<PhabricatorObjectHandle> $handles
21 */
22 public function setHandles(array $handles) {
23 assert_instances_of($handles, PhabricatorObjectHandle::class);
24 $this->handles = $handles;
25 return $this;
26 }
27
28 public function getHandles() {
29 return $this->handles;
30 }
31
32 public function setObjectPHID($object_phid) {
33 $this->objectPHID = $object_phid;
34 return $this;
35 }
36
37 public function getObjectPHID() {
38 return $this->objectPHID;
39 }
40
41 public function setTitle($title) {
42 $this->title = $title;
43 return $this;
44 }
45
46 public function getTitle() {
47 return $this->title;
48 }
49
50 public function buildDialog() {
51 $phid = $this->getObjectPHID();
52 $handles = $this->getHandles();
53 $object_handle = $handles[$phid];
54 unset($handles[$phid]);
55
56 return id(new AphrontDialogView())
57 ->setUser($this->getViewer())
58 ->setWidth(AphrontDialogView::WIDTH_FORM)
59 ->setTitle($this->getTitle())
60 ->setObjectList($this->buildBody($this->getViewer(), $handles))
61 ->addCancelButton($object_handle->getURI(), pht('Close'));
62 }
63
64 private function buildBody(PhabricatorUser $viewer, $handles) {
65
66 $list = id(new PHUIObjectItemListView())
67 ->setUser($viewer);
68 foreach ($handles as $handle) {
69 $item = id(new PHUIObjectItemView())
70 ->setHeader($handle->getFullName())
71 ->setHref($handle->getURI())
72 ->setDisabled($handle->isDisabled());
73
74 if ($handle->getImageURI()) {
75 $item->setImageURI($handle->getImageURI());
76 }
77
78 $list->addItem($item);
79 }
80
81 return $list;
82 }
83
84}