Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F17945885
D17021.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D17021.id.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -3476,6 +3476,7 @@
'PhabricatorProjectPointsProfileMenuItem' => 'applications/project/menuitem/PhabricatorProjectPointsProfileMenuItem.php',
'PhabricatorProjectProfileController' => 'applications/project/controller/PhabricatorProjectProfileController.php',
'PhabricatorProjectProfileMenuEngine' => 'applications/project/engine/PhabricatorProjectProfileMenuEngine.php',
+ 'PhabricatorProjectProfileMenuItem' => 'applications/search/menuitem/PhabricatorProjectProfileMenuItem.php',
'PhabricatorProjectProjectHasMemberEdgeType' => 'applications/project/edge/PhabricatorProjectProjectHasMemberEdgeType.php',
'PhabricatorProjectProjectHasObjectEdgeType' => 'applications/project/edge/PhabricatorProjectProjectHasObjectEdgeType.php',
'PhabricatorProjectProjectPHIDType' => 'applications/project/phid/PhabricatorProjectProjectPHIDType.php',
@@ -8613,6 +8614,7 @@
'PhabricatorProjectPointsProfileMenuItem' => 'PhabricatorProfileMenuItem',
'PhabricatorProjectProfileController' => 'PhabricatorProjectController',
'PhabricatorProjectProfileMenuEngine' => 'PhabricatorProfileMenuEngine',
+ 'PhabricatorProjectProfileMenuItem' => 'PhabricatorProfileMenuItem',
'PhabricatorProjectProjectHasMemberEdgeType' => 'PhabricatorEdgeType',
'PhabricatorProjectProjectHasObjectEdgeType' => 'PhabricatorEdgeType',
'PhabricatorProjectProjectPHIDType' => 'PhabricatorPHIDType',
diff --git a/src/applications/search/engine/PhabricatorProfileMenuEngine.php b/src/applications/search/engine/PhabricatorProfileMenuEngine.php
--- a/src/applications/search/engine/PhabricatorProfileMenuEngine.php
+++ b/src/applications/search/engine/PhabricatorProfileMenuEngine.php
@@ -73,7 +73,7 @@
}
$item_id = $request->getURIData('itemID');
- $item_list = $this->loadItems();
+ $item_list = $this->getItems();
$selected_item = null;
if (strlen($item_id)) {
@@ -174,6 +174,18 @@
->setBaseURI(new PhutilURI($this->getItemURI('')));
$menu_items = $this->getItems();
+ $filtered_items = array();
+ foreach ($menu_items as $menu_item) {
+ if ($menu_item->isDisabled()) {
+ continue;
+ }
+ $filtered_items[] = $menu_item;
+ }
+ $filtered_groups = mgroup($filtered_items, 'getMenuItemKey');
+ foreach ($filtered_groups as $group) {
+ $first_item = head($group);
+ $first_item->willBuildNavigationItems($group);
+ }
foreach ($menu_items as $menu_item) {
if ($menu_item->isDisabled()) {
diff --git a/src/applications/search/menuitem/PhabricatorProfileMenuItem.php b/src/applications/search/menuitem/PhabricatorProfileMenuItem.php
--- a/src/applications/search/menuitem/PhabricatorProfileMenuItem.php
+++ b/src/applications/search/menuitem/PhabricatorProfileMenuItem.php
@@ -12,6 +12,8 @@
abstract protected function newNavigationMenuItems(
PhabricatorProfileMenuItemConfiguration $config);
+ public function willBuildNavigationItems(array $items) {}
+
public function getMenuItemTypeIcon() {
return null;
}
diff --git a/src/applications/search/menuitem/PhabricatorProjectProfileMenuItem.php b/src/applications/search/menuitem/PhabricatorProjectProfileMenuItem.php
new file mode 100644
--- /dev/null
+++ b/src/applications/search/menuitem/PhabricatorProjectProfileMenuItem.php
@@ -0,0 +1,113 @@
+<?php
+
+final class PhabricatorProjectProfileMenuItem
+ extends PhabricatorProfileMenuItem {
+
+ const MENUITEMKEY = 'project';
+
+ private $project;
+
+ public function getMenuItemTypeIcon() {
+ return 'fa-briefcase';
+ }
+
+ public function getMenuItemTypeName() {
+ return pht('Project');
+ }
+
+ public function canAddToObject($object) {
+ return true;
+ }
+
+ public function attachProject($project) {
+ $this->project = $project;
+ return $this;
+ }
+
+ public function getProject() {
+ $project = $this->project;
+ if (!$project) {
+ return null;
+ } else if ($project->isArchived()) {
+ return null;
+ }
+ return $project;
+ }
+
+ public function willBuildNavigationItems(array $items) {
+ $viewer = $this->getViewer();
+ $project_phids = array();
+ foreach ($items as $item) {
+ $project_phids[] = $item->getMenuItemProperty('project');
+ }
+
+ $projects = id(new PhabricatorProjectQuery())
+ ->setViewer($viewer)
+ ->withPHIDs($project_phids)
+ ->needImages(true)
+ ->execute();
+
+ $projects = mpull($projects, null, 'getPHID');
+ foreach ($items as $item) {
+ $project_phid = $item->getMenuItemProperty('project');
+ $project = idx($projects, $project_phid, null);
+ $item->getMenuItem()->attachProject($project);
+ }
+ }
+
+ public function getDisplayName(
+ PhabricatorProfileMenuItemConfiguration $config) {
+ $project = $this->getProject();
+ if (!$project) {
+ return pht('(Restricted/Invalid Project)');
+ }
+ if (strlen($this->getName($config))) {
+ return $this->getName($config);
+ } else {
+ return $project->getName();
+ }
+ }
+
+ public function buildEditEngineFields(
+ PhabricatorProfileMenuItemConfiguration $config) {
+ return array(
+ id(new PhabricatorTextEditField())
+ ->setKey('name')
+ ->setLabel(pht('Name'))
+ ->setValue($this->getName($config)),
+ id(new PhabricatorDatasourceEditField())
+ ->setKey('project')
+ ->setLabel(pht('Project'))
+ ->setDatasource(new PhabricatorProjectDatasource())
+ ->setSingleValue($config->getMenuItemProperty('project')),
+ );
+ }
+
+ private function getName(
+ PhabricatorProfileMenuItemConfiguration $config) {
+ return $config->getMenuItemProperty('name');
+ }
+
+ protected function newNavigationMenuItems(
+ PhabricatorProfileMenuItemConfiguration $config) {
+
+ $project = $this->getProject();
+ if (!$project) {
+ return array();
+ }
+
+ $picture = $project->getProfileImageURI();
+ $name = $this->getDisplayName($config);
+ $href = $project->getURI();
+
+ $item = $this->newItem()
+ ->setHref($href)
+ ->setName($name)
+ ->setProfileImage($picture);
+
+ return array(
+ $item,
+ );
+ }
+
+}
diff --git a/src/applications/search/query/PhabricatorProfileMenuItemConfigurationQuery.php b/src/applications/search/query/PhabricatorProfileMenuItemConfigurationQuery.php
--- a/src/applications/search/query/PhabricatorProfileMenuItemConfigurationQuery.php
+++ b/src/applications/search/query/PhabricatorProfileMenuItemConfigurationQuery.php
@@ -66,6 +66,7 @@
unset($page[$key]);
continue;
}
+ $item_type = clone $item_type;
$item->attachMenuItem($item_type);
}
diff --git a/src/applications/search/storage/PhabricatorProfileMenuItemConfiguration.php b/src/applications/search/storage/PhabricatorProfileMenuItemConfiguration.php
--- a/src/applications/search/storage/PhabricatorProfileMenuItemConfiguration.php
+++ b/src/applications/search/storage/PhabricatorProfileMenuItemConfiguration.php
@@ -118,6 +118,10 @@
return $this->getMenuItem()->shouldEnableForObject($object);
}
+ public function willBuildNavigationItems(array $items) {
+ return $this->getMenuItem()->willBuildNavigationItems($items);
+ }
+
public function getSortKey() {
$order = $this->getMenuItemOrder();
if ($order === null) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Aug 1, 1:13 PM (4 d, 12 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
8692748
Default Alt Text
D17021.id.diff (7 KB)
Attached To
Mode
D17021: Add a basic ProjectProfileMenuItem
Attached
Detach File
Event Timeline
Log In to Comment