@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add a basic ProjectProfileMenuItem

Summary: Allows you to name and set a project as a menu item navigation element.

Test Plan: Add a project, no name, see project. Remove. Add a project and give it a short name (bugs) and see project link.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D17021

+135 -1
+2
src/__phutil_library_map__.php
··· 3476 3476 'PhabricatorProjectPointsProfileMenuItem' => 'applications/project/menuitem/PhabricatorProjectPointsProfileMenuItem.php', 3477 3477 'PhabricatorProjectProfileController' => 'applications/project/controller/PhabricatorProjectProfileController.php', 3478 3478 'PhabricatorProjectProfileMenuEngine' => 'applications/project/engine/PhabricatorProjectProfileMenuEngine.php', 3479 + 'PhabricatorProjectProfileMenuItem' => 'applications/search/menuitem/PhabricatorProjectProfileMenuItem.php', 3479 3480 'PhabricatorProjectProjectHasMemberEdgeType' => 'applications/project/edge/PhabricatorProjectProjectHasMemberEdgeType.php', 3480 3481 'PhabricatorProjectProjectHasObjectEdgeType' => 'applications/project/edge/PhabricatorProjectProjectHasObjectEdgeType.php', 3481 3482 'PhabricatorProjectProjectPHIDType' => 'applications/project/phid/PhabricatorProjectProjectPHIDType.php', ··· 8613 8614 'PhabricatorProjectPointsProfileMenuItem' => 'PhabricatorProfileMenuItem', 8614 8615 'PhabricatorProjectProfileController' => 'PhabricatorProjectController', 8615 8616 'PhabricatorProjectProfileMenuEngine' => 'PhabricatorProfileMenuEngine', 8617 + 'PhabricatorProjectProfileMenuItem' => 'PhabricatorProfileMenuItem', 8616 8618 'PhabricatorProjectProjectHasMemberEdgeType' => 'PhabricatorEdgeType', 8617 8619 'PhabricatorProjectProjectHasObjectEdgeType' => 'PhabricatorEdgeType', 8618 8620 'PhabricatorProjectProjectPHIDType' => 'PhabricatorPHIDType',
+13 -1
src/applications/search/engine/PhabricatorProfileMenuEngine.php
··· 73 73 } 74 74 75 75 $item_id = $request->getURIData('itemID'); 76 - $item_list = $this->loadItems(); 76 + $item_list = $this->getItems(); 77 77 78 78 $selected_item = null; 79 79 if (strlen($item_id)) { ··· 174 174 ->setBaseURI(new PhutilURI($this->getItemURI(''))); 175 175 176 176 $menu_items = $this->getItems(); 177 + $filtered_items = array(); 178 + foreach ($menu_items as $menu_item) { 179 + if ($menu_item->isDisabled()) { 180 + continue; 181 + } 182 + $filtered_items[] = $menu_item; 183 + } 184 + $filtered_groups = mgroup($filtered_items, 'getMenuItemKey'); 185 + foreach ($filtered_groups as $group) { 186 + $first_item = head($group); 187 + $first_item->willBuildNavigationItems($group); 188 + } 177 189 178 190 foreach ($menu_items as $menu_item) { 179 191 if ($menu_item->isDisabled()) {
+2
src/applications/search/menuitem/PhabricatorProfileMenuItem.php
··· 12 12 abstract protected function newNavigationMenuItems( 13 13 PhabricatorProfileMenuItemConfiguration $config); 14 14 15 + public function willBuildNavigationItems(array $items) {} 16 + 15 17 public function getMenuItemTypeIcon() { 16 18 return null; 17 19 }
+113
src/applications/search/menuitem/PhabricatorProjectProfileMenuItem.php
··· 1 + <?php 2 + 3 + final class PhabricatorProjectProfileMenuItem 4 + extends PhabricatorProfileMenuItem { 5 + 6 + const MENUITEMKEY = 'project'; 7 + 8 + private $project; 9 + 10 + public function getMenuItemTypeIcon() { 11 + return 'fa-briefcase'; 12 + } 13 + 14 + public function getMenuItemTypeName() { 15 + return pht('Project'); 16 + } 17 + 18 + public function canAddToObject($object) { 19 + return true; 20 + } 21 + 22 + public function attachProject($project) { 23 + $this->project = $project; 24 + return $this; 25 + } 26 + 27 + public function getProject() { 28 + $project = $this->project; 29 + if (!$project) { 30 + return null; 31 + } else if ($project->isArchived()) { 32 + return null; 33 + } 34 + return $project; 35 + } 36 + 37 + public function willBuildNavigationItems(array $items) { 38 + $viewer = $this->getViewer(); 39 + $project_phids = array(); 40 + foreach ($items as $item) { 41 + $project_phids[] = $item->getMenuItemProperty('project'); 42 + } 43 + 44 + $projects = id(new PhabricatorProjectQuery()) 45 + ->setViewer($viewer) 46 + ->withPHIDs($project_phids) 47 + ->needImages(true) 48 + ->execute(); 49 + 50 + $projects = mpull($projects, null, 'getPHID'); 51 + foreach ($items as $item) { 52 + $project_phid = $item->getMenuItemProperty('project'); 53 + $project = idx($projects, $project_phid, null); 54 + $item->getMenuItem()->attachProject($project); 55 + } 56 + } 57 + 58 + public function getDisplayName( 59 + PhabricatorProfileMenuItemConfiguration $config) { 60 + $project = $this->getProject(); 61 + if (!$project) { 62 + return pht('(Restricted/Invalid Project)'); 63 + } 64 + if (strlen($this->getName($config))) { 65 + return $this->getName($config); 66 + } else { 67 + return $project->getName(); 68 + } 69 + } 70 + 71 + public function buildEditEngineFields( 72 + PhabricatorProfileMenuItemConfiguration $config) { 73 + return array( 74 + id(new PhabricatorTextEditField()) 75 + ->setKey('name') 76 + ->setLabel(pht('Name')) 77 + ->setValue($this->getName($config)), 78 + id(new PhabricatorDatasourceEditField()) 79 + ->setKey('project') 80 + ->setLabel(pht('Project')) 81 + ->setDatasource(new PhabricatorProjectDatasource()) 82 + ->setSingleValue($config->getMenuItemProperty('project')), 83 + ); 84 + } 85 + 86 + private function getName( 87 + PhabricatorProfileMenuItemConfiguration $config) { 88 + return $config->getMenuItemProperty('name'); 89 + } 90 + 91 + protected function newNavigationMenuItems( 92 + PhabricatorProfileMenuItemConfiguration $config) { 93 + 94 + $project = $this->getProject(); 95 + if (!$project) { 96 + return array(); 97 + } 98 + 99 + $picture = $project->getProfileImageURI(); 100 + $name = $this->getDisplayName($config); 101 + $href = $project->getURI(); 102 + 103 + $item = $this->newItem() 104 + ->setHref($href) 105 + ->setName($name) 106 + ->setProfileImage($picture); 107 + 108 + return array( 109 + $item, 110 + ); 111 + } 112 + 113 + }
+1
src/applications/search/query/PhabricatorProfileMenuItemConfigurationQuery.php
··· 66 66 unset($page[$key]); 67 67 continue; 68 68 } 69 + $item_type = clone $item_type; 69 70 $item->attachMenuItem($item_type); 70 71 } 71 72
+4
src/applications/search/storage/PhabricatorProfileMenuItemConfiguration.php
··· 118 118 return $this->getMenuItem()->shouldEnableForObject($object); 119 119 } 120 120 121 + public function willBuildNavigationItems(array $items) { 122 + return $this->getMenuItem()->willBuildNavigationItems($items); 123 + } 124 + 121 125 public function getSortKey() { 122 126 $order = $this->getMenuItemOrder(); 123 127 if ($order === null) {