forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPHUIApplicationMenuView.php
112 lines (87 loc) · 2.23 KB
/
PHUIApplicationMenuView.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
final class PHUIApplicationMenuView extends Phobject {
private $viewer;
private $crumbs;
private $searchEngine;
private $profileMenu;
private $items = array();
public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
}
public function getViewer() {
return $this->viewer;
}
public function addLabel($name) {
$item = id(new PHUIListItemView())
->setName($name);
return $this->addItem($item);
}
public function addLink($name, $href) {
$item = id(new PHUIListItemView())
->setName($name)
->setHref($href);
return $this->addItem($item);
}
public function setProfileMenu(
AphrontSideNavFilterView $nav) {
$this->profileMenu = $nav;
return $this;
}
public function getProfileMenu() {
return $this->profileMenu;
}
public function addItem(PHUIListItemView $item) {
$this->items[] = $item;
return $this;
}
public function setSearchEngine(PhabricatorApplicationSearchEngine $engine) {
$this->searchEngine = $engine;
return $this;
}
public function getSearchEngine() {
return $this->searchEngine;
}
public function setCrumbs(PHUICrumbsView $crumbs) {
$this->crumbs = $crumbs;
return $this;
}
public function getCrumbs() {
return $this->crumbs;
}
public function buildListView() {
$viewer = $this->getViewer();
$view = id(new PHUIListView())
->setUser($viewer);
$profile_menu = $this->getProfileMenu();
if ($profile_menu) {
foreach ($profile_menu->getMenu()->getItems() as $item) {
if ($item->getHideInApplicationMenu()) {
continue;
}
$item = clone $item;
$view->addMenuItem($item);
}
}
$crumbs = $this->getCrumbs();
if ($crumbs) {
$actions = $crumbs->getActions();
if ($actions) {
$view->newLabel(pht('Create'));
foreach ($crumbs->getActions() as $action) {
$view->addMenuItem($action);
}
}
}
$engine = $this->getSearchEngine();
if ($engine) {
$engine
->setViewer($viewer)
->addNavigationItems($view);
}
foreach ($this->items as $item) {
$view->addMenuItem($item);
}
return $view;
}
}