Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F17908998
D17021.id41041.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D17021.id41041.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
@@ -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,90 @@
+<?php
+
+final class PhabricatorProjectProfileMenuItem
+ extends PhabricatorProfileMenuItem {
+
+ const MENUITEMKEY = 'project';
+
+ public function getMenuItemTypeIcon() {
+ return 'fa-briefcase';
+ }
+
+ public function getMenuItemTypeName() {
+ return pht('Project');
+ }
+
+ public function canAddToObject($object) {
+ return true;
+ }
+
+ 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 = $projects[$project_phid];
+ $item->attachProject($project);
+ }
+ }
+
+ public function getDisplayName(
+ PhabricatorProfileMenuItemConfiguration $config) {
+ if (strlen($this->getName($config))) {
+ return $this->getName($config);
+ } else {
+ $project = $this->getProject();
+ 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();
+
+ $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/storage/PhabricatorProfileMenuItemConfiguration.php b/src/applications/search/storage/PhabricatorProfileMenuItemConfiguration.php
--- a/src/applications/search/storage/PhabricatorProfileMenuItemConfiguration.php
+++ b/src/applications/search/storage/PhabricatorProfileMenuItemConfiguration.php
@@ -16,6 +16,7 @@
private $profileObject = self::ATTACHABLE;
private $menuItem = self::ATTACHABLE;
+ private $project = self::ATTACHABLE;
const VISIBILITY_DEFAULT = 'default';
const VISIBILITY_VISIBLE = 'visible';
@@ -85,6 +86,15 @@
return $this->assertAttached($this->profileObject);
}
+ public function attachProject($project) {
+ $this->project = $project;
+ return $this;
+ }
+
+ public function getProject() {
+ return $this->assertAttached($this->project);
+ }
+
public function setMenuItemProperty($key, $value) {
$this->menuItemProperties[$key] = $value;
return $this;
@@ -118,6 +128,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
Wed, Jul 30, 2:06 PM (7 h, 9 m ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
8743434
Default Alt Text
D17021.id41041.diff (6 KB)
Attached To
Mode
D17021: Add a basic ProjectProfileMenuItem
Attached
Detach File
Event Timeline
Log In to Comment