diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index a70eb1d5ae..6815ddda25 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3476,6 +3476,7 @@ phutil_register_library_map(array( '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 @@ phutil_register_library_map(array( '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 index 7126a12ddd..d930b31314 100644 --- a/src/applications/search/engine/PhabricatorProfileMenuEngine.php +++ b/src/applications/search/engine/PhabricatorProfileMenuEngine.php @@ -73,7 +73,7 @@ abstract class PhabricatorProfileMenuEngine extends Phobject { } $item_id = $request->getURIData('itemID'); - $item_list = $this->loadItems(); + $item_list = $this->getItems(); $selected_item = null; if (strlen($item_id)) { @@ -174,6 +174,18 @@ abstract class PhabricatorProfileMenuEngine extends Phobject { ->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 index f37cab236c..c47d9afe8e 100644 --- a/src/applications/search/menuitem/PhabricatorProfileMenuItem.php +++ b/src/applications/search/menuitem/PhabricatorProfileMenuItem.php @@ -12,6 +12,8 @@ abstract class PhabricatorProfileMenuItem extends Phobject { 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 index 0000000000..002a3fcace --- /dev/null +++ b/src/applications/search/menuitem/PhabricatorProjectProfileMenuItem.php @@ -0,0 +1,113 @@ +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 index 2109ee1dbe..f8172638c3 100644 --- a/src/applications/search/query/PhabricatorProfileMenuItemConfigurationQuery.php +++ b/src/applications/search/query/PhabricatorProfileMenuItemConfigurationQuery.php @@ -66,6 +66,7 @@ final class PhabricatorProfileMenuItemConfigurationQuery 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 index 46aa03e25d..3a9c0effc6 100644 --- a/src/applications/search/storage/PhabricatorProfileMenuItemConfiguration.php +++ b/src/applications/search/storage/PhabricatorProfileMenuItemConfiguration.php @@ -118,6 +118,10 @@ final class PhabricatorProfileMenuItemConfiguration return $this->getMenuItem()->shouldEnableForObject($object); } + public function willBuildNavigationItems(array $items) { + return $this->getMenuItem()->willBuildNavigationItems($items); + } + public function getSortKey() { $order = $this->getMenuItemOrder(); if ($order === null) {