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