Page MenuHomePhabricator

D17021.id41042.diff
No OneTemporary

D17021.id41042.diff

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,97 @@
+<?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 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->getMenuItem()->attachProject($project);
+ }
+ }
+
+ public function getDisplayName(
+ PhabricatorProfileMenuItemConfiguration $config) {
+ if (strlen($this->getName($config))) {
+ return $this->getName($config);
+ } else {
+ $project = $this->project;
+ 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->project;
+
+ $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
@@ -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

Mime Type
text/plain
Expires
Sat, Aug 2, 12:51 AM (4 d, 12 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
8817437
Default Alt Text
D17021.id41042.diff (6 KB)

Event Timeline