@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Automatically build mobile menus from navigation, and clean up external ProfileMenu API

Summary:
Depends on D20355. Ref T13275. Ref T13247. Currently, "Hamburger" menus are not automatically built from navigation menus. However, this is (I'm almost completely sure?) a reasonable and appropriate default behavior, and saves us some code around profile menus.

With this rule in place, we can remove `setApplicationMenu()` and `getApplicationMenu()` from `StandardPageView`, since they have no callers.

This also updates a lot of profile menu callsites to a new API which is added in the next change.

Test Plan: See the next two changes.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13275, T13247

Differential Revision: https://secure.phabricator.com/D20356

+91 -154
+3 -2
src/applications/favorites/engineextension/PhabricatorFavoritesMainMenuBarExtension.php
··· 20 20 21 21 $dropdown = $this->newDropdown($viewer); 22 22 if (!$dropdown) { 23 - return null; 23 + return array(); 24 24 } 25 25 26 26 $favorites_menu = id(new PHUIButtonView()) ··· 59 59 $menu_engine->setController($controller); 60 60 } 61 61 62 - $filter_view = $menu_engine->buildNavigation(); 62 + $filter_view = $menu_engine->newProfileMenuItemViewList() 63 + ->newNavigationView(); 63 64 64 65 $menu_view = $filter_view->getMenu(); 65 66 $item_views = $menu_view->getItems();
+2 -42
src/applications/home/controller/PhabricatorHomeController.php
··· 1 1 <?php 2 2 3 - abstract class PhabricatorHomeController extends PhabricatorController { 4 - 5 - private $home; 6 - private $profileMenu; 7 - 8 - public function buildApplicationMenu() { 9 - $menu = $this->newApplicationMenu(); 10 - 11 - $profile_menu = $this->getProfileMenu(); 12 - if ($profile_menu) { 13 - $menu->setProfileMenu($profile_menu); 14 - } 15 - 16 - return $menu; 17 - } 18 - 19 - protected function getProfileMenu() { 20 - if (!$this->profileMenu) { 21 - $viewer = $this->getViewer(); 22 - $applications = id(new PhabricatorApplicationQuery()) 23 - ->setViewer($viewer) 24 - ->withClasses(array('PhabricatorHomeApplication')) 25 - ->withInstalled(true) 26 - ->execute(); 27 - $home = head($applications); 28 - if (!$home) { 29 - return null; 30 - } 31 - 32 - $engine = id(new PhabricatorHomeProfileMenuEngine()) 33 - ->setViewer($viewer) 34 - ->setController($this) 35 - ->setProfileObject($home) 36 - ->setCustomPHID($viewer->getPHID()); 37 - 38 - $this->profileMenu = $engine->buildNavigation(); 39 - } 40 - 41 - return $this->profileMenu; 42 - } 43 - 44 - } 3 + abstract class PhabricatorHomeController 4 + extends PhabricatorController {}
+3 -2
src/applications/people/controller/PhabricatorPeopleProfileBadgesController.php
··· 30 30 $crumbs->addTextCrumb(pht('Badges')); 31 31 $crumbs->setBorder(true); 32 32 33 - $nav = $this->getProfileMenu(); 34 - $nav->selectFilter(PhabricatorPeopleProfileMenuEngine::ITEM_BADGES); 33 + $nav = $this->newNavigation( 34 + $user, 35 + PhabricatorPeopleProfileMenuEngine::ITEM_BADGES); 35 36 36 37 // Best option? 37 38 $badges = id(new PhabricatorBadgesQuery())
+3 -2
src/applications/people/controller/PhabricatorPeopleProfileCommitsController.php
··· 32 32 $crumbs->addTextCrumb(pht('Recent Commits')); 33 33 $crumbs->setBorder(true); 34 34 35 - $nav = $this->getProfileMenu(); 36 - $nav->selectFilter(PhabricatorPeopleProfileMenuEngine::ITEM_COMMITS); 35 + $nav = $this->newNavigation( 36 + $user, 37 + PhabricatorPeopleProfileMenuEngine::ITEM_COMMITS); 37 38 38 39 $view = id(new PHUITwoColumnView()) 39 40 ->setHeader($header)
+20 -29
src/applications/people/controller/PhabricatorPeopleProfileController.php
··· 4 4 extends PhabricatorPeopleController { 5 5 6 6 private $user; 7 - private $profileMenu; 8 7 9 8 public function shouldRequireAdmin() { 10 9 return false; ··· 17 16 18 17 public function getUser() { 19 18 return $this->user; 20 - } 21 - 22 - public function buildApplicationMenu() { 23 - $menu = $this->newApplicationMenu(); 24 - 25 - $profile_menu = $this->getProfileMenu(); 26 - if ($profile_menu) { 27 - $menu->setProfileMenu($profile_menu); 28 - } 29 - 30 - return $menu; 31 - } 32 - 33 - protected function getProfileMenu() { 34 - if (!$this->profileMenu) { 35 - $user = $this->getUser(); 36 - if ($user) { 37 - $viewer = $this->getViewer(); 38 - 39 - $engine = id(new PhabricatorPeopleProfileMenuEngine()) 40 - ->setViewer($viewer) 41 - ->setProfileObject($user); 42 - 43 - $this->profileMenu = $engine->buildNavigation(); 44 - } 45 - } 46 - 47 - return $this->profileMenu; 48 19 } 49 20 50 21 protected function buildApplicationCrumbs() { ··· 136 107 } 137 108 138 109 return $header; 110 + } 111 + 112 + final protected function newNavigation( 113 + PhabricatorUser $user, 114 + $item_identifier) { 115 + 116 + $viewer = $this->getViewer(); 117 + 118 + $engine = id(new PhabricatorPeopleProfileMenuEngine()) 119 + ->setViewer($viewer) 120 + ->setController($this) 121 + ->setProfileObject($user); 122 + 123 + $view_list = $engine->newProfileMenuItemViewList(); 124 + 125 + $view_list->setSelectedViewWithItemIdentifier($item_identifier); 126 + 127 + $navigation = $view_list->newNavigationView(); 128 + 129 + return $navigation; 139 130 } 140 131 141 132 }
+3 -2
src/applications/people/controller/PhabricatorPeopleProfileManageController.php
··· 29 29 $properties = $this->buildPropertyView($user); 30 30 $name = $user->getUsername(); 31 31 32 - $nav = $this->getProfileMenu(); 33 - $nav->selectFilter(PhabricatorPeopleProfileMenuEngine::ITEM_MANAGE); 32 + $nav = $this->newNavigation( 33 + $user, 34 + PhabricatorPeopleProfileMenuEngine::ITEM_MANAGE); 34 35 35 36 $crumbs = $this->buildApplicationCrumbs(); 36 37 $crumbs->addTextCrumb(pht('Manage'));
+3 -2
src/applications/people/controller/PhabricatorPeopleProfileRevisionsController.php
··· 32 32 $crumbs->addTextCrumb(pht('Recent Revisions')); 33 33 $crumbs->setBorder(true); 34 34 35 - $nav = $this->getProfileMenu(); 36 - $nav->selectFilter(PhabricatorPeopleProfileMenuEngine::ITEM_REVISIONS); 35 + $nav = $this->newNavigation( 36 + $user, 37 + PhabricatorPeopleProfileMenuEngine::ITEM_REVISIONS); 37 38 38 39 $view = id(new PHUITwoColumnView()) 39 40 ->setHeader($header)
+3 -2
src/applications/people/controller/PhabricatorPeopleProfileTasksController.php
··· 32 32 $crumbs->addTextCrumb(pht('Assigned Tasks')); 33 33 $crumbs->setBorder(true); 34 34 35 - $nav = $this->getProfileMenu(); 36 - $nav->selectFilter(PhabricatorPeopleProfileMenuEngine::ITEM_TASKS); 35 + $nav = $this->newNavigation( 36 + $user, 37 + PhabricatorPeopleProfileMenuEngine::ITEM_TASKS); 37 38 38 39 $view = id(new PHUITwoColumnView()) 39 40 ->setHeader($header)
+4 -3
src/applications/people/controller/PhabricatorPeopleProfileViewController.php
··· 64 64 $calendar, 65 65 )); 66 66 67 - $nav = $this->getProfileMenu(); 68 - $nav->selectFilter(PhabricatorPeopleProfileMenuEngine::ITEM_PROFILE); 67 + $navigation = $this->newNavigation( 68 + $user, 69 + PhabricatorPeopleProfileMenuEngine::ITEM_PROFILE); 69 70 70 71 $crumbs = $this->buildApplicationCrumbs(); 71 72 $crumbs->setBorder(true); 72 73 73 74 return $this->newPage() 74 75 ->setTitle($user->getUsername()) 75 - ->setNavigation($nav) 76 + ->setNavigation($navigation) 76 77 ->setCrumbs($crumbs) 77 78 ->setPageObjectPHIDs( 78 79 array(
+6 -13
src/applications/project/controller/PhabricatorProjectBoardViewController.php
··· 172 172 return $content; 173 173 } 174 174 175 - $nav = $this->newWorkboardProfileMenu(); 175 + $nav = $this->newNavigation( 176 + $project, 177 + PhabricatorProject::ITEM_WORKBOARD); 176 178 177 179 $crumbs = $this->buildApplicationCrumbs(); 178 180 $crumbs->addTextCrumb(pht('Workboard')); ··· 719 721 ->appendChild($board) 720 722 ->addClass('project-board-wrapper'); 721 723 722 - $nav = $this->newWorkboardProfileMenu(); 724 + $nav = $this->newNavigation( 725 + $project, 726 + PhabricatorProject::ITEM_WORKBOARD); 723 727 724 728 $divider = id(new PHUIListItemView()) 725 729 ->setType(PHUIListItemView::TYPE_DIVIDER); ··· 1501 1505 'to enable it. Only users who can edit this project can restore '. 1502 1506 'the workboard.')) 1503 1507 ->addCancelButton($profile_uri); 1504 - } 1505 - 1506 - private function newWorkboardProfileMenu() { 1507 - $default_item = id(new PhabricatorProfileMenuItemConfiguration()) 1508 - ->setBuiltinKey(PhabricatorProject::ITEM_WORKBOARD); 1509 - 1510 - $menu = parent::getProfileMenu($default_item); 1511 - 1512 - $menu->addClass('project-board-nav'); 1513 - 1514 - return $menu; 1515 1508 } 1516 1509 1517 1510 }
+19 -24
src/applications/project/controller/PhabricatorProjectController.php
··· 84 84 return null; 85 85 } 86 86 87 - public function buildApplicationMenu() { 88 - $menu = $this->newApplicationMenu(); 89 - 90 - $profile_menu = $this->getProfileMenu(); 91 - if ($profile_menu) { 92 - $menu->setProfileMenu($profile_menu); 93 - } 94 - 95 - $menu->setSearchEngine(new PhabricatorProjectSearchEngine()); 96 - 97 - return $menu; 98 - } 99 - 100 - protected function getProfileMenu($default_item = null) { 101 - if (!$this->profileMenu) { 102 - $engine = $this->getProfileMenuEngine(); 103 - if ($engine) { 104 - $this->profileMenu = $engine->buildNavigation($default_item); 105 - } 106 - } 107 - 108 - return $this->profileMenu; 109 - } 110 - 111 87 protected function buildApplicationCrumbs() { 112 88 return $this->newApplicationCrumbs('profile'); 113 89 } ··· 205 181 $result[] = '#'.$tag; 206 182 } 207 183 return implode(', ', $result); 184 + } 185 + 186 + final protected function newNavigation( 187 + PhabricatorProject $project, 188 + $item_identifier) { 189 + 190 + $engine = $this->getProfileMenuEngine(); 191 + 192 + $view_list = $engine->newProfileMenuItemViewList(); 193 + 194 + $view_list->setSelectedViewWithItemIdentifier($item_identifier); 195 + 196 + $navigation = $view_list->newNavigationView(); 197 + 198 + if ($item_identifier === PhabricatorProject::ITEM_WORKBOARD) { 199 + $navigation->addClass('project-board-nav'); 200 + } 201 + 202 + return $navigation; 208 203 } 209 204 210 205 }
+3 -2
src/applications/project/controller/PhabricatorProjectManageController.php
··· 37 37 new PhabricatorProjectTransactionQuery()); 38 38 $timeline->setShouldTerminate(true); 39 39 40 - $nav = $this->getProfileMenu(); 41 - $nav->selectFilter(PhabricatorProject::ITEM_MANAGE); 40 + $nav = $this->newNavigation( 41 + $project, 42 + PhabricatorProject::ITEM_MANAGE); 42 43 43 44 $crumbs = $this->buildApplicationCrumbs(); 44 45 $crumbs->addTextCrumb(pht('Manage'));
+3 -2
src/applications/project/controller/PhabricatorProjectMembersViewController.php
··· 36 36 ->setUserPHIDs($project->getWatcherPHIDs()) 37 37 ->setShowNote(true); 38 38 39 - $nav = $this->getProfileMenu(); 40 - $nav->selectFilter(PhabricatorProject::ITEM_MEMBERS); 39 + $nav = $this->newNavigation( 40 + $project, 41 + PhabricatorProject::ITEM_MEMBERS); 41 42 42 43 $crumbs = $this->buildApplicationCrumbs(); 43 44 $crumbs->addTextCrumb(pht('Members'));
+3 -2
src/applications/project/controller/PhabricatorProjectProfileController.php
··· 74 74 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 75 75 ->setUserPHIDs($project->getWatcherPHIDs()); 76 76 77 - $nav = $this->getProfileMenu(); 78 - $nav->selectFilter(PhabricatorProject::ITEM_PROFILE); 77 + $nav = $this->newNavigation( 78 + $project, 79 + PhabricatorProject::ITEM_PROFILE); 79 80 80 81 $stories = id(new PhabricatorFeedQuery()) 81 82 ->setViewer($viewer)
+3 -2
src/applications/project/controller/PhabricatorProjectSubprojectsController.php
··· 77 77 $milestones, 78 78 $subprojects); 79 79 80 - $nav = $this->getProfileMenu(); 81 - $nav->selectFilter(PhabricatorProject::ITEM_SUBPROJECTS); 80 + $nav = $this->newNavigation( 81 + $project, 82 + PhabricatorProject::ITEM_SUBPROJECTS); 82 83 83 84 $crumbs = $this->buildApplicationCrumbs(); 84 85 $crumbs->addTextCrumb(pht('Subprojects'));
+1 -1
src/applications/project/controller/PhabricatorProjectViewController.php
··· 18 18 $project = $this->getProject(); 19 19 20 20 $engine = $this->getProfileMenuEngine(); 21 - $default = $engine->getDefaultItem(); 21 + $default = $engine->getDefaultMenuItemConfiguration(); 22 22 23 23 // If defaults are broken somehow, serve the manage page. See T13033 for 24 24 // discussion.
-2
src/applications/search/controller/PhabricatorApplicationSearchController.php
··· 387 387 require_celerity_resource('application-search-view-css'); 388 388 389 389 return $this->newPage() 390 - ->setApplicationMenu($this->buildApplicationMenu()) 391 390 ->setTitle(pht('Query: %s', $title)) 392 391 ->setCrumbs($crumbs) 393 392 ->setNavigation($nav) ··· 611 610 ->setFooter($lists); 612 611 613 612 return $this->newPage() 614 - ->setApplicationMenu($this->buildApplicationMenu()) 615 613 ->setTitle(pht('Saved Queries')) 616 614 ->setCrumbs($crumbs) 617 615 ->setNavigation($nav)
+9 -20
src/view/page/PhabricatorStandardPageView.php
··· 32 32 return $this->showFooter; 33 33 } 34 34 35 - public function setApplicationMenu($application_menu) { 36 - // NOTE: For now, this can either be a PHUIListView or a 37 - // PHUIApplicationMenuView. 38 - 39 - $this->applicationMenu = $application_menu; 40 - return $this; 41 - } 42 - 43 - public function getApplicationMenu() { 44 - return $this->applicationMenu; 45 - } 46 - 47 35 public function setApplicationName($application_name) { 48 36 $this->applicationName = $application_name; 49 37 return $this; ··· 345 333 $menu->setController($this->getController()); 346 334 } 347 335 348 - $application_menu = $this->getApplicationMenu(); 336 + $application_menu = $this->applicationMenu; 349 337 if ($application_menu) { 350 338 if ($application_menu instanceof PHUIApplicationMenuView) { 351 339 $crumbs = $this->getCrumbs(); ··· 865 853 public function produceAphrontResponse() { 866 854 $controller = $this->getController(); 867 855 868 - if (!$this->getApplicationMenu()) { 869 - $application_menu = $controller->buildApplicationMenu(); 870 - if ($application_menu) { 871 - $this->setApplicationMenu($application_menu); 872 - } 873 - } 874 - 875 856 $viewer = $this->getUser(); 876 857 if ($viewer && $viewer->getPHID()) { 877 858 $object_phids = $this->pageObjects; ··· 887 868 $response = id(new AphrontAjaxResponse()) 888 869 ->setContent($content); 889 870 } else { 871 + // See T13247. Try to find some navigational menu items to create a 872 + // mobile navigation menu from. 873 + $application_menu = $controller->buildApplicationMenu(); 874 + if (!$application_menu) { 875 + $application_menu = $this->getNavigation()->getMenu(); 876 + } 877 + $this->applicationMenu = $application_menu; 878 + 890 879 $content = $this->render(); 891 880 892 881 $response = id(new AphrontWebpageResponse())