Skip to content

Commit 971a272

Browse files
author
epriestley
committed
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
1 parent 47bf382 commit 971a272

18 files changed

+91
-154
lines changed

src/applications/favorites/engineextension/PhabricatorFavoritesMainMenuBarExtension.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function buildMainMenus() {
2020

2121
$dropdown = $this->newDropdown($viewer);
2222
if (!$dropdown) {
23-
return null;
23+
return array();
2424
}
2525

2626
$favorites_menu = id(new PHUIButtonView())
@@ -59,7 +59,8 @@ private function newDropdown(PhabricatorUser $viewer) {
5959
$menu_engine->setController($controller);
6060
}
6161

62-
$filter_view = $menu_engine->buildNavigation();
62+
$filter_view = $menu_engine->newProfileMenuItemViewList()
63+
->newNavigationView();
6364

6465
$menu_view = $filter_view->getMenu();
6566
$item_views = $menu_view->getItems();
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,4 @@
11
<?php
22

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 {}

src/applications/people/controller/PhabricatorPeopleProfileBadgesController.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ public function handleRequest(AphrontRequest $request) {
3030
$crumbs->addTextCrumb(pht('Badges'));
3131
$crumbs->setBorder(true);
3232

33-
$nav = $this->getProfileMenu();
34-
$nav->selectFilter(PhabricatorPeopleProfileMenuEngine::ITEM_BADGES);
33+
$nav = $this->newNavigation(
34+
$user,
35+
PhabricatorPeopleProfileMenuEngine::ITEM_BADGES);
3536

3637
// Best option?
3738
$badges = id(new PhabricatorBadgesQuery())

src/applications/people/controller/PhabricatorPeopleProfileCommitsController.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ public function handleRequest(AphrontRequest $request) {
3232
$crumbs->addTextCrumb(pht('Recent Commits'));
3333
$crumbs->setBorder(true);
3434

35-
$nav = $this->getProfileMenu();
36-
$nav->selectFilter(PhabricatorPeopleProfileMenuEngine::ITEM_COMMITS);
35+
$nav = $this->newNavigation(
36+
$user,
37+
PhabricatorPeopleProfileMenuEngine::ITEM_COMMITS);
3738

3839
$view = id(new PHUITwoColumnView())
3940
->setHeader($header)

src/applications/people/controller/PhabricatorPeopleProfileController.php

+20-29
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ abstract class PhabricatorPeopleProfileController
44
extends PhabricatorPeopleController {
55

66
private $user;
7-
private $profileMenu;
87

98
public function shouldRequireAdmin() {
109
return false;
@@ -19,34 +18,6 @@ public function getUser() {
1918
return $this->user;
2019
}
2120

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-
}
49-
5021
protected function buildApplicationCrumbs() {
5122
$crumbs = parent::buildApplicationCrumbs();
5223

@@ -138,4 +109,24 @@ public function buildProfileHeader() {
138109
return $header;
139110
}
140111

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;
130+
}
131+
141132
}

src/applications/people/controller/PhabricatorPeopleProfileManageController.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ public function handleRequest(AphrontRequest $request) {
2929
$properties = $this->buildPropertyView($user);
3030
$name = $user->getUsername();
3131

32-
$nav = $this->getProfileMenu();
33-
$nav->selectFilter(PhabricatorPeopleProfileMenuEngine::ITEM_MANAGE);
32+
$nav = $this->newNavigation(
33+
$user,
34+
PhabricatorPeopleProfileMenuEngine::ITEM_MANAGE);
3435

3536
$crumbs = $this->buildApplicationCrumbs();
3637
$crumbs->addTextCrumb(pht('Manage'));

src/applications/people/controller/PhabricatorPeopleProfileRevisionsController.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ public function handleRequest(AphrontRequest $request) {
3232
$crumbs->addTextCrumb(pht('Recent Revisions'));
3333
$crumbs->setBorder(true);
3434

35-
$nav = $this->getProfileMenu();
36-
$nav->selectFilter(PhabricatorPeopleProfileMenuEngine::ITEM_REVISIONS);
35+
$nav = $this->newNavigation(
36+
$user,
37+
PhabricatorPeopleProfileMenuEngine::ITEM_REVISIONS);
3738

3839
$view = id(new PHUITwoColumnView())
3940
->setHeader($header)

src/applications/people/controller/PhabricatorPeopleProfileTasksController.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ public function handleRequest(AphrontRequest $request) {
3232
$crumbs->addTextCrumb(pht('Assigned Tasks'));
3333
$crumbs->setBorder(true);
3434

35-
$nav = $this->getProfileMenu();
36-
$nav->selectFilter(PhabricatorPeopleProfileMenuEngine::ITEM_TASKS);
35+
$nav = $this->newNavigation(
36+
$user,
37+
PhabricatorPeopleProfileMenuEngine::ITEM_TASKS);
3738

3839
$view = id(new PHUITwoColumnView())
3940
->setHeader($header)

src/applications/people/controller/PhabricatorPeopleProfileViewController.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,16 @@ public function handleRequest(AphrontRequest $request) {
6464
$calendar,
6565
));
6666

67-
$nav = $this->getProfileMenu();
68-
$nav->selectFilter(PhabricatorPeopleProfileMenuEngine::ITEM_PROFILE);
67+
$navigation = $this->newNavigation(
68+
$user,
69+
PhabricatorPeopleProfileMenuEngine::ITEM_PROFILE);
6970

7071
$crumbs = $this->buildApplicationCrumbs();
7172
$crumbs->setBorder(true);
7273

7374
return $this->newPage()
7475
->setTitle($user->getUsername())
75-
->setNavigation($nav)
76+
->setNavigation($navigation)
7677
->setCrumbs($crumbs)
7778
->setPageObjectPHIDs(
7879
array(

src/applications/project/controller/PhabricatorProjectBoardViewController.php

+6-13
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ public function handleRequest(AphrontRequest $request) {
172172
return $content;
173173
}
174174

175-
$nav = $this->newWorkboardProfileMenu();
175+
$nav = $this->newNavigation(
176+
$project,
177+
PhabricatorProject::ITEM_WORKBOARD);
176178

177179
$crumbs = $this->buildApplicationCrumbs();
178180
$crumbs->addTextCrumb(pht('Workboard'));
@@ -719,7 +721,9 @@ public function handleRequest(AphrontRequest $request) {
719721
->appendChild($board)
720722
->addClass('project-board-wrapper');
721723

722-
$nav = $this->newWorkboardProfileMenu();
724+
$nav = $this->newNavigation(
725+
$project,
726+
PhabricatorProject::ITEM_WORKBOARD);
723727

724728
$divider = id(new PHUIListItemView())
725729
->setType(PHUIListItemView::TYPE_DIVIDER);
@@ -1503,15 +1507,4 @@ private function buildDisabledContent(PhabricatorProject $project) {
15031507
->addCancelButton($profile_uri);
15041508
}
15051509

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-
}
1516-
15171510
}

src/applications/project/controller/PhabricatorProjectController.php

+19-24
Original file line numberDiff line numberDiff line change
@@ -84,30 +84,6 @@ protected function loadProject() {
8484
return null;
8585
}
8686

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-
11187
protected function buildApplicationCrumbs() {
11288
return $this->newApplicationCrumbs('profile');
11389
}
@@ -207,4 +183,23 @@ public function renderHashtags(array $tags) {
207183
return implode(', ', $result);
208184
}
209185

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;
203+
}
204+
210205
}

src/applications/project/controller/PhabricatorProjectManageController.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ public function handleRequest(AphrontRequest $request) {
3737
new PhabricatorProjectTransactionQuery());
3838
$timeline->setShouldTerminate(true);
3939

40-
$nav = $this->getProfileMenu();
41-
$nav->selectFilter(PhabricatorProject::ITEM_MANAGE);
40+
$nav = $this->newNavigation(
41+
$project,
42+
PhabricatorProject::ITEM_MANAGE);
4243

4344
$crumbs = $this->buildApplicationCrumbs();
4445
$crumbs->addTextCrumb(pht('Manage'));

src/applications/project/controller/PhabricatorProjectMembersViewController.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ public function handleRequest(AphrontRequest $request) {
3636
->setUserPHIDs($project->getWatcherPHIDs())
3737
->setShowNote(true);
3838

39-
$nav = $this->getProfileMenu();
40-
$nav->selectFilter(PhabricatorProject::ITEM_MEMBERS);
39+
$nav = $this->newNavigation(
40+
$project,
41+
PhabricatorProject::ITEM_MEMBERS);
4142

4243
$crumbs = $this->buildApplicationCrumbs();
4344
$crumbs->addTextCrumb(pht('Members'));

src/applications/project/controller/PhabricatorProjectProfileController.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ public function handleRequest(AphrontRequest $request) {
7474
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
7575
->setUserPHIDs($project->getWatcherPHIDs());
7676

77-
$nav = $this->getProfileMenu();
78-
$nav->selectFilter(PhabricatorProject::ITEM_PROFILE);
77+
$nav = $this->newNavigation(
78+
$project,
79+
PhabricatorProject::ITEM_PROFILE);
7980

8081
$stories = id(new PhabricatorFeedQuery())
8182
->setViewer($viewer)

src/applications/project/controller/PhabricatorProjectSubprojectsController.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ public function handleRequest(AphrontRequest $request) {
7777
$milestones,
7878
$subprojects);
7979

80-
$nav = $this->getProfileMenu();
81-
$nav->selectFilter(PhabricatorProject::ITEM_SUBPROJECTS);
80+
$nav = $this->newNavigation(
81+
$project,
82+
PhabricatorProject::ITEM_SUBPROJECTS);
8283

8384
$crumbs = $this->buildApplicationCrumbs();
8485
$crumbs->addTextCrumb(pht('Subprojects'));

src/applications/project/controller/PhabricatorProjectViewController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function handleRequest(AphrontRequest $request) {
1818
$project = $this->getProject();
1919

2020
$engine = $this->getProfileMenuEngine();
21-
$default = $engine->getDefaultItem();
21+
$default = $engine->getDefaultMenuItemConfiguration();
2222

2323
// If defaults are broken somehow, serve the manage page. See T13033 for
2424
// discussion.

src/applications/search/controller/PhabricatorApplicationSearchController.php

-2
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,6 @@ private function processSearchRequest() {
387387
require_celerity_resource('application-search-view-css');
388388

389389
return $this->newPage()
390-
->setApplicationMenu($this->buildApplicationMenu())
391390
->setTitle(pht('Query: %s', $title))
392391
->setCrumbs($crumbs)
393392
->setNavigation($nav)
@@ -611,7 +610,6 @@ private function processEditRequest() {
611610
->setFooter($lists);
612611

613612
return $this->newPage()
614-
->setApplicationMenu($this->buildApplicationMenu())
615613
->setTitle(pht('Saved Queries'))
616614
->setCrumbs($crumbs)
617615
->setNavigation($nav)

0 commit comments

Comments
 (0)