Skip to content

Commit dfee135

Browse files
author
Chad Little
committed
Basic structure for MenuItem on Home
Summary: Ref T11957, builds out `/home/menu/` as a basic structure for adding/editing the homepage menu. Test Plan: visit `/home/menu/` and add items to global and personal. Not wired to anything. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T11957 Differential Revision: https://secure.phabricator.com/D17180
1 parent 2941b34 commit dfee135

File tree

7 files changed

+240
-0
lines changed

7 files changed

+240
-0
lines changed

src/__phutil_library_map__.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2820,9 +2820,14 @@
28202820
'PhabricatorHeraldContentSource' => 'applications/herald/contentsource/PhabricatorHeraldContentSource.php',
28212821
'PhabricatorHighSecurityRequestExceptionHandler' => 'aphront/handler/PhabricatorHighSecurityRequestExceptionHandler.php',
28222822
'PhabricatorHomeApplication' => 'applications/home/application/PhabricatorHomeApplication.php',
2823+
'PhabricatorHomeConstants' => 'applications/home/constants/PhabricatorHomeConstants.php',
28232824
'PhabricatorHomeController' => 'applications/home/controller/PhabricatorHomeController.php',
28242825
'PhabricatorHomeMainController' => 'applications/home/controller/PhabricatorHomeMainController.php',
2826+
'PhabricatorHomeManageProfileMenuItem' => 'applications/home/menuitem/PhabricatorHomeManageProfileMenuItem.php',
2827+
'PhabricatorHomeMenuController' => 'applications/home/controller/PhabricatorHomeMenuController.php',
2828+
'PhabricatorHomeMenuItemController' => 'applications/home/controller/PhabricatorHomeMenuItemController.php',
28252829
'PhabricatorHomePreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorHomePreferencesSettingsPanel.php',
2830+
'PhabricatorHomeProfileMenuEngine' => 'applications/home/engine/PhabricatorHomeProfileMenuEngine.php',
28262831
'PhabricatorHomeQuickCreateController' => 'applications/home/controller/PhabricatorHomeQuickCreateController.php',
28272832
'PhabricatorHovercardEngineExtension' => 'applications/search/engineextension/PhabricatorHovercardEngineExtension.php',
28282833
'PhabricatorHovercardEngineExtensionModule' => 'applications/search/engineextension/PhabricatorHovercardEngineExtensionModule.php',
@@ -7861,9 +7866,14 @@
78617866
'PhabricatorHeraldContentSource' => 'PhabricatorContentSource',
78627867
'PhabricatorHighSecurityRequestExceptionHandler' => 'PhabricatorRequestExceptionHandler',
78637868
'PhabricatorHomeApplication' => 'PhabricatorApplication',
7869+
'PhabricatorHomeConstants' => 'PhabricatorHomeController',
78647870
'PhabricatorHomeController' => 'PhabricatorController',
78657871
'PhabricatorHomeMainController' => 'PhabricatorHomeController',
7872+
'PhabricatorHomeManageProfileMenuItem' => 'PhabricatorProfileMenuItem',
7873+
'PhabricatorHomeMenuController' => 'PhabricatorHomeController',
7874+
'PhabricatorHomeMenuItemController' => 'PhabricatorHomeController',
78667875
'PhabricatorHomePreferencesSettingsPanel' => 'PhabricatorSettingsPanel',
7876+
'PhabricatorHomeProfileMenuEngine' => 'PhabricatorProfileMenuEngine',
78677877
'PhabricatorHomeQuickCreateController' => 'PhabricatorHomeController',
78687878
'PhabricatorHovercardEngineExtension' => 'Phobject',
78697879
'PhabricatorHovercardEngineExtensionModule' => 'PhabricatorConfigModule',

src/applications/home/application/PhabricatorHomeApplication.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public function getRoutes() {
2727
'/(?P<only>home)/' => 'PhabricatorHomeMainController',
2828
'/home/' => array(
2929
'create/' => 'PhabricatorHomeQuickCreateController',
30+
'menu/' => array(
31+
'' => 'PhabricatorHomeMenuController',
32+
'(?P<type>global|personal)/item/' => $this->getProfileMenuRouting(
33+
'PhabricatorHomeMenuItemController'),
34+
),
3035
),
3136
);
3237
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
final class PhabricatorHomeConstants
4+
extends PhabricatorHomeController {
5+
6+
const ITEM_LAUNCHER = 'home.launcher';
7+
const ITEM_MANAGE = 'home.manage.menu';
8+
9+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
final class PhabricatorHomeMenuController extends PhabricatorHomeController {
4+
5+
public function shouldAllowPublic() {
6+
return false;
7+
}
8+
9+
public function handleRequest(AphrontRequest $request) {
10+
$viewer = $request->getViewer();
11+
12+
$menu = id(new PHUIObjectItemListView())
13+
->setUser($viewer);
14+
15+
$menu->addItem(
16+
id(new PHUIObjectItemView())
17+
->setHeader(pht('Personal Menu Items'))
18+
->setHref($this->getApplicationURI('menu/personal/item/configure/'))
19+
->setImageURI($viewer->getProfileImageURI())
20+
->addAttribute(pht('Edit the menu for your personal account.')));
21+
22+
$icon = id(new PHUIIconView())
23+
->setIcon('fa-globe')
24+
->setBackground('bg-blue');
25+
26+
$menu->addItem(
27+
id(new PHUIObjectItemView())
28+
->setHeader(pht('Global Menu Items'))
29+
->setHref($this->getApplicationURI('menu/global/item/configure/'))
30+
->setImageIcon($icon)
31+
->addAttribute(pht('Edit the global default menu for all users.')));
32+
33+
$crumbs = $this->buildApplicationCrumbs();
34+
$crumbs->addTextCrumb(pht('Manage'));
35+
$crumbs->setBorder(true);
36+
37+
$box = id(new PHUIObjectBoxView())
38+
->setObjectList($menu);
39+
40+
$header = id(new PHUIHeaderView())
41+
->setHeader(pht('Manage Home Menu'))
42+
->setHeaderIcon('fa-home');
43+
44+
$view = id(new PHUITwoColumnView())
45+
->setHeader($header)
46+
->setFooter(array(
47+
$box,
48+
));
49+
50+
return $this->newPage()
51+
->setTitle(pht('Manage Home Menu'))
52+
->setCrumbs($crumbs)
53+
->appendChild($view);
54+
55+
}
56+
57+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
final class PhabricatorHomeMenuItemController
4+
extends PhabricatorHomeController {
5+
6+
public function handleRequest(AphrontRequest $request) {
7+
$viewer = $this->getViewer();
8+
$type = $request->getURIData('type');
9+
$custom_phid = null;
10+
if ($type == 'personal') {
11+
$custom_phid = $viewer->getPHID();
12+
}
13+
14+
$application = 'PhabricatorHomeApplication';
15+
$home_app = id(new PhabricatorApplicationQuery())
16+
->setViewer($viewer)
17+
->withClasses(array($application))
18+
->withInstalled(true)
19+
->executeOne();
20+
21+
$engine = id(new PhabricatorHomeProfileMenuEngine())
22+
->setProfileObject($home_app)
23+
->setCustomPHID($custom_phid)
24+
->setController($this);
25+
26+
return $engine->buildResponse();
27+
}
28+
29+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
final class PhabricatorHomeProfileMenuEngine
4+
extends PhabricatorProfileMenuEngine {
5+
6+
protected function isMenuEngineConfigurable() {
7+
return true;
8+
}
9+
10+
protected function getItemURI($path) {
11+
$object = $this->getProfileObject();
12+
$custom = $this->getCustomPHID();
13+
14+
if ($custom) {
15+
return "/home/menu/personal/item/{$path}";
16+
} else {
17+
return "/home/menu/global/item/{$path}";
18+
}
19+
}
20+
21+
protected function getBuiltinProfileItems($object) {
22+
$viewer = $this->getViewer();
23+
$items = array();
24+
$custom_phid = $this->getCustomPHID();
25+
26+
$applications = id(new PhabricatorApplicationQuery())
27+
->setViewer($viewer)
28+
->withInstalled(true)
29+
->withUnlisted(false)
30+
->withLaunchable(true)
31+
->execute();
32+
33+
foreach ($applications as $application) {
34+
if (!$application->isPinnedByDefault($viewer)) {
35+
continue;
36+
}
37+
38+
$properties = array(
39+
'name' => $application->getName(),
40+
'application' => $application->getPHID(),
41+
);
42+
43+
$items[] = $this->newItem()
44+
->setBuiltinKey($application->getPHID())
45+
->setMenuItemKey(PhabricatorApplicationProfileMenuItem::MENUITEMKEY)
46+
->setMenuItemProperties($properties);
47+
}
48+
49+
// Single Manage Item, switches URI based on admin/user
50+
$items[] = $this->newItem()
51+
->setBuiltinKey(PhabricatorHomeConstants::ITEM_MANAGE)
52+
->setMenuItemKey(
53+
PhabricatorHomeManageProfileMenuItem::MENUITEMKEY);
54+
55+
return $items;
56+
}
57+
58+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
final class PhabricatorHomeManageProfileMenuItem
4+
extends PhabricatorProfileMenuItem {
5+
6+
const MENUITEMKEY = 'home.manage.menu';
7+
8+
public function getMenuItemTypeName() {
9+
return pht('Manage Home Menu');
10+
}
11+
12+
private function getDefaultName() {
13+
return pht('Manage');
14+
}
15+
16+
public function canHideMenuItem(
17+
PhabricatorProfileMenuItemConfiguration $config) {
18+
return false;
19+
}
20+
21+
public function canMakeDefault(
22+
PhabricatorProfileMenuItemConfiguration $config) {
23+
return false;
24+
}
25+
26+
public function getDisplayName(
27+
PhabricatorProfileMenuItemConfiguration $config) {
28+
$name = $config->getMenuItemProperty('name');
29+
30+
if (strlen($name)) {
31+
return $name;
32+
}
33+
34+
return $this->getDefaultName();
35+
}
36+
37+
public function buildEditEngineFields(
38+
PhabricatorProfileMenuItemConfiguration $config) {
39+
return array(
40+
id(new PhabricatorTextEditField())
41+
->setKey('name')
42+
->setLabel(pht('Name'))
43+
->setPlaceholder($this->getDefaultName())
44+
->setValue($config->getMenuItemProperty('name')),
45+
);
46+
}
47+
48+
protected function newNavigationMenuItems(
49+
PhabricatorProfileMenuItemConfiguration $config) {
50+
$viewer = $this->getViewer();
51+
52+
if ($viewer->isLoggedIn()) {
53+
$admin = $viewer->getIsAdmin();
54+
$name = $this->getDisplayName($config);
55+
$icon = 'fa-pencil';
56+
$href = '/home/menu/personal/item/configure/';
57+
if ($admin) {
58+
$href = '/home/menu/';
59+
}
60+
61+
$item = $this->newItem()
62+
->setHref($href)
63+
->setName($name)
64+
->setIcon($icon);
65+
}
66+
67+
return array(
68+
$item,
69+
);
70+
}
71+
72+
}

0 commit comments

Comments
 (0)