Page MenuHomePhabricator

D17021.id41039.diff
No OneTemporary

D17021.id41039.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
@@ -3460,6 +3460,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',
@@ -8581,6 +8582,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
@@ -164,6 +164,18 @@
->appendChild($content);
}
+ public function willBuildNavigationItems(array $items) {
+ $filtered_items = array();
+ foreach ($items as $menu_item) {
+ if ($menu_item->isDisabled()) {
+ continue;
+ }
+ $filtered_items[] = $menu_item;
+ }
+ $filtered_items = mgroup($filtered_items, 'getMenuItemKey');
+ // Um, do something?
+ }
+
public function buildNavigation() {
if ($this->navigation) {
return $this->navigation;
@@ -174,6 +186,7 @@
->setBaseURI(new PhutilURI($this->getItemURI('')));
$menu_items = $this->getItems();
+ $this->willBuildNavigationalItems($menu_items);
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,11 @@
abstract protected function newNavigationMenuItems(
PhabricatorProfileMenuItemConfiguration $config);
+ public function willBuildNavigationMenuItems(
+ PhabricatorProfileMenuItemConfiguration $config) {
+ return null;
+ }
+
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,88 @@
+<?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 willBuildNavigationMenuItems(
+ PhabricatorProfileMenuItemConfiguration $config) {
+ $phid = $config->getMenuItemProperty('project');
+ return $phid;
+ }
+
+ public function getDisplayName(
+ PhabricatorProfileMenuItemConfiguration $config) {
+ if (strlen($this->getName($config))) {
+ return $this->getName($config);
+ } else {
+ $project = $this->getProject($config);
+ 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');
+ }
+
+ private function getProject(
+ PhabricatorProfileMenuItemConfiguration $config) {
+ $viewer = $this->getViewer();
+ $phid = $config->getMenuItemProperty('project');
+ $project = id(new PhabricatorProjectQuery())
+ ->setViewer($viewer)
+ ->withPHIDs(array($phid))
+ ->needImages(true)
+ ->executeOne();
+
+ return $project;
+ }
+
+ protected function newNavigationMenuItems(
+ PhabricatorProfileMenuItemConfiguration $config) {
+
+ $project = $this->getProject($config);
+
+ $picture = $project->getProfileImageURI();
+ $name = $this->getDisplayName($config);
+ $href = $project->getURI();
+
+ $item = $this->newItem()
+ ->setHref($href)
+ ->setName($name)
+ ->setProfileImage($picture);
+
+ return array(
+ $item,
+ );
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Aug 4 2025, 6:04 PM (4 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
8938370
Default Alt Text
D17021.id41039.diff (5 KB)

Event Timeline