@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 upstream/main 104 lines 3.0 kB view raw
1<?php 2 3abstract class PhrictionController extends PhabricatorController { 4 5 private $showingWelcomeDocument = false; 6 7 public function setShowingWelcomeDocument($show_welcome) { 8 $this->showingWelcomeDocument = $show_welcome; 9 return $this; 10 11 } 12 13 public function buildSideNavView($for_app = false) { 14 $user = $this->getRequest()->getUser(); 15 16 $nav = new AphrontSideNavFilterView(); 17 $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); 18 19 if ($for_app) { 20 $nav->addFilter('create', pht('New Document')); 21 $nav->addFilter('/phriction/', pht('Index')); 22 } 23 24 id(new PhrictionDocumentSearchEngine()) 25 ->setViewer($user) 26 ->addNavigationItems($nav->getMenu()); 27 28 $nav->selectFilter(null); 29 30 return $nav; 31 } 32 33 public function buildApplicationMenu() { 34 return $this->buildSideNavView(true)->getMenu(); 35 } 36 37 protected function buildApplicationCrumbs() { 38 $crumbs = parent::buildApplicationCrumbs(); 39 40 if (get_class($this) != PhrictionListController::class) { 41 $crumbs->addAction( 42 id(new PHUIListItemView()) 43 ->setName(pht('Index')) 44 ->setHref('/phriction/') 45 ->setIcon('fa-home')); 46 } 47 48 if (!$this->showingWelcomeDocument) { 49 $crumbs->addAction( 50 id(new PHUIListItemView()) 51 ->setName(pht('New Document')) 52 ->setHref('/phriction/new/?slug='.$this->getDocumentSlug()) 53 ->setWorkflow(true) 54 ->setIcon('fa-plus-square')); 55 } 56 57 return $crumbs; 58 } 59 60 public function renderBreadcrumbs($slug) { 61 $ancestor_handles = array(); 62 $ancestral_slugs = PhabricatorSlug::getAncestry($slug); 63 $ancestral_slugs[] = $slug; 64 if ($ancestral_slugs) { 65 $empty_slugs = array_fill_keys($ancestral_slugs, null); 66 $ancestors = id(new PhrictionDocumentQuery()) 67 ->setViewer($this->getRequest()->getUser()) 68 ->withSlugs($ancestral_slugs) 69 ->execute(); 70 $ancestors = mpull($ancestors, null, 'getSlug'); 71 72 $ancestor_phids = mpull($ancestors, 'getPHID'); 73 $handles = array(); 74 if ($ancestor_phids) { 75 $handles = $this->loadViewerHandles($ancestor_phids); 76 } 77 78 $ancestor_handles = array(); 79 foreach ($ancestral_slugs as $slug) { 80 if (isset($ancestors[$slug])) { 81 $ancestor_handles[] = $handles[$ancestors[$slug]->getPHID()]; 82 } else { 83 $handle = new PhabricatorObjectHandle(); 84 $handle->setName(PhabricatorSlug::getDefaultTitle($slug)); 85 $handle->setURI(PhrictionDocument::getSlugURI($slug)); 86 $ancestor_handles[] = $handle; 87 } 88 } 89 } 90 91 $breadcrumbs = array(); 92 foreach ($ancestor_handles as $ancestor_handle) { 93 $breadcrumbs[] = id(new PHUICrumbView()) 94 ->setName($ancestor_handle->getName()) 95 ->setHref($ancestor_handle->getUri()); 96 } 97 return $breadcrumbs; 98 } 99 100 protected function getDocumentSlug() { 101 return ''; 102 } 103 104}