@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
3/**
4 * Convenience class for rendering a single handle.
5 *
6 * This class simplifies rendering a single handle, and improves loading and
7 * caching semantics in the rendering pipeline by loading data at the last
8 * moment.
9 */
10
11final class PHUIHandleView
12 extends AphrontView {
13
14 private $handleList;
15 private $handlePHID;
16 private $asTag;
17 private $asText;
18 private $useShortName;
19 private $showHovercard;
20 private $glyphLimit;
21
22 public function setHandleList(PhabricatorHandleList $list) {
23 $this->handleList = $list;
24 return $this;
25 }
26
27 public function setHandlePHID($phid) {
28 $this->handlePHID = $phid;
29 return $this;
30 }
31
32 public function setAsTag($tag) {
33 $this->asTag = $tag;
34 return $this;
35 }
36
37 public function setAsText($as_text) {
38 $this->asText = $as_text;
39 return $this;
40 }
41
42 public function setUseShortName($short) {
43 $this->useShortName = $short;
44 return $this;
45 }
46
47 public function setShowHovercard($hovercard) {
48 $this->showHovercard = $hovercard;
49 return $this;
50 }
51
52 public function setGlyphLimit($glyph_limit) {
53 $this->glyphLimit = $glyph_limit;
54 return $this;
55 }
56
57 public function getGlyphLimit() {
58 return $this->glyphLimit;
59 }
60
61 public function render() {
62 $handle = $this->handleList[$this->handlePHID];
63
64 if ($this->asTag) {
65 $tag = $handle->renderTag();
66
67 if ($this->showHovercard) {
68 $tag->setPHID($handle->getPHID());
69 }
70
71 return $tag;
72 }
73
74 if ($this->asText) {
75 return $handle->getLinkName();
76 }
77
78 if ($this->useShortName) {
79 $name = $handle->getName();
80 } else {
81 $name = $handle->getLinkName();
82 }
83
84 $glyph_limit = $this->getGlyphLimit();
85 if ($glyph_limit) {
86 $name = id(new PhutilUTF8StringTruncator())
87 ->setMaximumGlyphs($glyph_limit)
88 ->truncateString($name);
89 }
90
91 if ($this->showHovercard) {
92 $link = $handle->renderHovercardLink($name);
93 } else {
94 $link = $handle->renderLink($name);
95 }
96
97 return $link;
98 }
99
100}