@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 PHUICrumbView extends AphrontView {
4
5 private $name;
6 private $href;
7 private $strikethrough = false;
8 private $icon;
9 private $isLastCrumb;
10 private $workflow;
11 private $aural;
12 private $alwaysVisible;
13
14 public function setAural($aural) {
15 $this->aural = $aural;
16 return $this;
17 }
18
19 public function getAural() {
20 return $this->aural;
21 }
22
23 /**
24 * Make this crumb always visible, even on devices where it would normally
25 * be hidden.
26 *
27 * @param bool $always_visible True to make the crumb always visible.
28 * @return $this
29 */
30 public function setAlwaysVisible($always_visible) {
31 $this->alwaysVisible = $always_visible;
32 return $this;
33 }
34
35 public function getAlwaysVisible() {
36 return $this->alwaysVisible;
37 }
38
39 /**
40 * @param bool $workflow
41 * @return $this
42 */
43 public function setWorkflow($workflow) {
44 $this->workflow = $workflow;
45 return $this;
46 }
47
48 public function setName($name) {
49 $this->name = $name;
50 return $this;
51 }
52
53 public function getName() {
54 return $this->name;
55 }
56
57 public function setHref($href) {
58 $this->href = $href;
59 return $this;
60 }
61
62 /**
63 * Render this crumb as strike-through.
64 *
65 * @param bool $strikethrough True to render the crumb strike-through.
66 * @return $this
67 */
68 public function setStrikethrough(bool $strikethrough) {
69 $this->strikethrough = $strikethrough;
70 return $this;
71 }
72
73 public function setIcon($icon) {
74 $this->icon = $icon;
75 return $this;
76 }
77
78 protected function canAppendChild() {
79 return false;
80 }
81
82 public function setIsLastCrumb($is_last_crumb) {
83 $this->isLastCrumb = $is_last_crumb;
84 return $this;
85 }
86
87 public function render() {
88 $classes = array(
89 'phui-crumb-view',
90 );
91
92 $aural = null;
93 if ($this->aural !== null) {
94 $aural = javelin_tag(
95 'span',
96 array(
97 'aural' => true,
98 ),
99 $this->aural);
100 }
101
102 $icon = null;
103 if ($this->icon) {
104 $classes[] = 'phui-crumb-has-icon';
105 $icon = id(new PHUIIconView())
106 ->setIcon($this->icon);
107 }
108
109 if ($this->strikethrough) {
110 $classes[] = 'phui-crumb-strikethrough';
111 }
112
113 // Surround the crumb name with spaces so that double clicking it only
114 // selects the crumb itself.
115 $name = array(' ', $this->name);
116
117 $name = phutil_tag(
118 'span',
119 array(
120 'class' => 'phui-crumb-name',
121 ),
122 $name);
123
124 // Because of text-overflow and safari, put the second space on the
125 // outside of the element.
126 $name = array($name, ' ');
127
128 $divider = null;
129 if (!$this->isLastCrumb) {
130 $divider = id(new PHUIIconView())
131 ->setIcon('fa-angle-right')
132 ->addClass('phui-crumb-divider')
133 ->addClass('phui-crumb-view');
134 } else {
135 $classes[] = 'phabricator-last-crumb';
136 }
137
138 if ($this->getAlwaysVisible()) {
139 $classes[] = 'phui-crumb-always-visible';
140 }
141
142 $tag = javelin_tag(
143 $this->href ? 'a' : 'span',
144 array(
145 'sigil' => $this->workflow ? 'workflow' : null,
146 'href' => $this->href,
147 'class' => implode(' ', $classes),
148 ),
149 array($aural, $icon, $name));
150
151 return array($tag, $divider);
152 }
153}