Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/view/phui/PHUITabView.php
12249 views
1
<?php
2
3
final class PHUITabView extends AphrontTagView {
4
5
private $icon;
6
private $name;
7
private $key;
8
private $keyLocked;
9
private $contentID;
10
private $color;
11
12
public function setKey($key) {
13
if ($this->keyLocked) {
14
throw new Exception(
15
pht(
16
'Attempting to change the key of a tab with a locked key ("%s").',
17
$this->key));
18
}
19
20
$this->key = $key;
21
return $this;
22
}
23
24
public function hasKey() {
25
return ($this->key !== null);
26
}
27
28
public function getKey() {
29
if (!$this->hasKey()) {
30
throw new PhutilInvalidStateException('setKey');
31
}
32
33
return $this->key;
34
}
35
36
public function lockKey() {
37
if (!$this->hasKey()) {
38
throw new PhutilInvalidStateException('setKey');
39
}
40
41
$this->keyLocked = true;
42
43
return $this;
44
}
45
46
public function setName($name) {
47
$this->name = $name;
48
return $this;
49
}
50
51
public function getName() {
52
return $this->name;
53
}
54
55
public function setIcon(PHUIIconView $icon) {
56
$this->icon = $icon;
57
return $this;
58
}
59
60
public function getIcon() {
61
return $this->icon;
62
}
63
64
public function getContentID() {
65
if ($this->contentID === null) {
66
$this->contentID = celerity_generate_unique_node_id();
67
}
68
69
return $this->contentID;
70
}
71
72
public function setColor($color) {
73
$this->color = $color;
74
return $this;
75
}
76
77
public function getColor() {
78
return $this->color;
79
}
80
81
public function newMenuItem() {
82
$item = id(new PHUIListItemView())
83
->setName($this->getName())
84
->setKey($this->getKey())
85
->setType(PHUIListItemView::TYPE_LINK)
86
->setHref('#')
87
->addSigil('phui-tab-view')
88
->setMetadata(
89
array(
90
'tabKey' => $this->getKey(),
91
));
92
93
$icon = $this->getIcon();
94
if ($icon) {
95
$item->setIcon($icon->getIconName());
96
}
97
98
$color = $this->getColor();
99
if ($color !== null) {
100
$item->setStatusColor($color);
101
}
102
103
return $item;
104
}
105
106
}
107
108