@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 PhabricatorProfileMenuItemView
4 extends Phobject {
5
6 private $config;
7 private $uri;
8 private $name;
9 private $icon;
10 private $iconImage;
11 private $disabled;
12 private $tooltip;
13 private $actions = array();
14 private $counts = array();
15 private $images = array();
16 private $progressBars = array();
17 private $isExternalLink;
18 private $specialType;
19
20 public function setMenuItemConfiguration(
21 PhabricatorProfileMenuItemConfiguration $config) {
22 $this->config = $config;
23 return $this;
24 }
25
26 public function getMenuItemConfiguration() {
27 return $this->config;
28 }
29
30 public function setURI($uri) {
31 $this->uri = $uri;
32 return $this;
33 }
34
35 public function getURI() {
36 return $this->uri;
37 }
38
39 public function setName($name) {
40 $this->name = $name;
41 return $this;
42 }
43
44 public function getName() {
45 return $this->name;
46 }
47
48 public function setIcon($icon) {
49 $this->icon = $icon;
50 return $this;
51 }
52
53 public function getIcon() {
54 return $this->icon;
55 }
56
57 public function setIconImage($icon_image) {
58 $this->iconImage = $icon_image;
59 return $this;
60 }
61
62 public function getIconImage() {
63 return $this->iconImage;
64 }
65
66 public function setDisabled($disabled) {
67 $this->disabled = $disabled;
68 return $this;
69 }
70
71 public function getDisabled() {
72 return $this->disabled;
73 }
74
75 public function setTooltip($tooltip) {
76 $this->tooltip = $tooltip;
77 return $this;
78 }
79
80 public function getTooltip() {
81 return $this->tooltip;
82 }
83
84 public function newAction($uri) {
85 $this->actions[] = $uri;
86 return null;
87 }
88
89 public function newCount($count) {
90 $this->counts[] = $count;
91 return null;
92 }
93
94 public function newProfileImage($src) {
95 $this->images[] = $src;
96 return null;
97 }
98
99 public function newProgressBar($bar) {
100 $this->progressBars[] = $bar;
101 return null;
102 }
103
104 public function setIsExternalLink($is_external) {
105 $this->isExternalLink = $is_external;
106 return $this;
107 }
108
109 public function getIsExternalLink() {
110 return $this->isExternalLink;
111 }
112
113 public function setIsLabel($is_label) {
114 return $this->setSpecialType('label');
115 }
116
117 public function getIsLabel() {
118 return $this->isSpecialType('label');
119 }
120
121 public function setIsDivider($is_divider) {
122 return $this->setSpecialType('divider');
123 }
124
125 public function getIsDivider() {
126 return $this->isSpecialType('divider');
127 }
128
129 private function setSpecialType($type) {
130 $this->specialType = $type;
131 return $this;
132 }
133
134 private function isSpecialType($type) {
135 return ($this->specialType === $type);
136 }
137
138 public function newListItemView() {
139 $view = id(new PHUIListItemView())
140 ->setName($this->getName());
141
142 $uri = $this->getURI();
143 if (phutil_nonempty_string($uri)) {
144 if ($this->getIsExternalLink()) {
145 if (!PhabricatorEnv::isValidURIForLink($uri)) {
146 $uri = '#';
147 }
148 $view->setRel('noreferrer');
149 }
150
151 $view->setHref($uri);
152 }
153
154 $icon = $this->getIcon();
155 if ($icon) {
156 $view->setIcon($icon);
157 }
158
159 $icon_image = $this->getIconImage();
160 if ($icon_image) {
161 $view->setProfileImage($icon_image);
162 }
163
164 if ($this->getDisabled()) {
165 $view->setDisabled(true);
166 }
167
168 if ($this->getIsLabel()) {
169 $view->setType(PHUIListItemView::TYPE_LABEL);
170 }
171
172 if ($this->getIsDivider()) {
173 $view
174 ->setType(PHUIListItemView::TYPE_DIVIDER)
175 ->addClass('phui-divider');
176 }
177
178 $tooltip = $this->getTooltip();
179 if (phutil_nonempty_string($tooltip)) {
180 $view->setTooltip($tooltip);
181 }
182
183 if ($this->images) {
184 require_celerity_resource('people-picture-menu-item-css');
185 foreach ($this->images as $image_src) {
186 $classes = array();
187 $classes[] = 'people-menu-image';
188
189 if ($this->getDisabled()) {
190 $classes[] = 'phui-image-disabled';
191 }
192
193 $image = phutil_tag(
194 'img',
195 array(
196 'src' => $image_src,
197 'class' => implode(' ', $classes),
198 'alt' => pht('Profile picture'),
199 ));
200
201 $image = phutil_tag(
202 'div',
203 array(
204 'class' => 'people-menu-image-container',
205 ),
206 $image);
207
208 $view->appendChild($image);
209 }
210 }
211
212 foreach ($this->counts as $count) {
213 $view->appendChild(
214 phutil_tag(
215 'span',
216 array(
217 'class' => 'phui-list-item-count',
218 ),
219 $count));
220 }
221
222 foreach ($this->actions as $action) {
223 $view->setActionIcon('fa-pencil', $action);
224 }
225
226 foreach ($this->progressBars as $bar) {
227 $view->appendChild($bar);
228 }
229
230 return $view;
231 }
232
233}