Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/view/phui/PHUICrumbsView.php
12249 views
1
<?php
2
3
final class PHUICrumbsView extends AphrontView {
4
5
private $crumbs = array();
6
private $actions = array();
7
private $border;
8
9
protected function canAppendChild() {
10
return false;
11
}
12
13
14
/**
15
* Convenience method for adding a simple crumb with just text, or text and
16
* a link.
17
*
18
* @param string Text of the crumb.
19
* @param string? Optional href for the crumb.
20
* @return this
21
*/
22
public function addTextCrumb($text, $href = null) {
23
return $this->addCrumb(
24
id(new PHUICrumbView())
25
->setName($text)
26
->setHref($href));
27
}
28
29
public function addCrumb(PHUICrumbView $crumb) {
30
$this->crumbs[] = $crumb;
31
return $this;
32
}
33
34
public function addAction(PHUIListItemView $action) {
35
$this->actions[] = $action;
36
return $this;
37
}
38
39
public function setBorder($border) {
40
$this->border = $border;
41
return $this;
42
}
43
44
public function getActions() {
45
return $this->actions;
46
}
47
48
public function render() {
49
require_celerity_resource('phui-crumbs-view-css');
50
51
$action_view = null;
52
if ($this->actions) {
53
// TODO: This block of code takes "PHUIListItemView" objects and turns
54
// them into some weird abomination by reading most of their properties
55
// out. Some day, this workflow should render the items and CSS should
56
// resytle them in place without needing a wholly separate set of
57
// DOM nodes.
58
59
$actions = array();
60
foreach ($this->actions as $action) {
61
if ($action->getType() == PHUIListItemView::TYPE_DIVIDER) {
62
$actions[] = phutil_tag(
63
'span',
64
array(
65
'class' => 'phui-crumb-action-divider',
66
));
67
continue;
68
}
69
70
$icon = null;
71
if ($action->getIcon()) {
72
$icon_name = $action->getIcon();
73
if ($action->getDisabled()) {
74
$icon_name .= ' lightgreytext';
75
}
76
77
$icon = id(new PHUIIconView())
78
->setIcon($icon_name);
79
80
}
81
82
$action_classes = $action->getClasses();
83
$action_classes[] = 'phui-crumbs-action';
84
85
$name = null;
86
if ($action->getName()) {
87
$name = phutil_tag(
88
'span',
89
array(
90
'class' => 'phui-crumbs-action-name',
91
),
92
$action->getName());
93
} else {
94
$action_classes[] = 'phui-crumbs-action-icon';
95
}
96
97
$action_sigils = $action->getSigils();
98
if ($action->getWorkflow()) {
99
$action_sigils[] = 'workflow';
100
}
101
102
if ($action->getDisabled()) {
103
$action_classes[] = 'phui-crumbs-action-disabled';
104
}
105
106
$actions[] = javelin_tag(
107
'a',
108
array(
109
'href' => $action->getHref(),
110
'class' => implode(' ', $action_classes),
111
'sigil' => implode(' ', $action_sigils),
112
'style' => $action->getStyle(),
113
'meta' => $action->getMetadata(),
114
),
115
array(
116
$icon,
117
$name,
118
));
119
}
120
121
$action_view = phutil_tag(
122
'div',
123
array(
124
'class' => 'phui-crumbs-actions',
125
),
126
$actions);
127
}
128
129
if ($this->crumbs) {
130
last($this->crumbs)->setIsLastCrumb(true);
131
}
132
133
$classes = array();
134
$classes[] = 'phui-crumbs-view';
135
if ($this->border) {
136
$classes[] = 'phui-crumbs-border';
137
}
138
139
return phutil_tag(
140
'div',
141
array(
142
'class' => implode(' ', $classes),
143
),
144
array(
145
$action_view,
146
$this->crumbs,
147
));
148
}
149
150
}
151
152