diff --git a/src/applications/differential/controller/DifferentialRevisionViewController.php b/src/applications/differential/controller/DifferentialRevisionViewController.php index d1fbe3ad05..dfbcaa74ff 100644 --- a/src/applications/differential/controller/DifferentialRevisionViewController.php +++ b/src/applications/differential/controller/DifferentialRevisionViewController.php @@ -527,22 +527,16 @@ final class DifferentialRevisionViewController extends DifferentialController { $viewer, $revision); - $parent_key = DifferentialRevisionHasParentRelationship::RELATIONSHIPKEY; - $child_key = DifferentialRevisionHasChildRelationship::RELATIONSHIPKEY; + $revision_actions = array( + DifferentialRevisionHasParentRelationship::RELATIONSHIPKEY, + DifferentialRevisionHasChildRelationship::RELATIONSHIPKEY, + ); - $revision_submenu = array(); + $revision_submenu = $relationship_list->newActionSubmenu($revision_actions) + ->setName(pht('Edit Related Revisions...')) + ->setIcon('fa-cog'); - $revision_submenu[] = $relationship_list->getRelationship($parent_key) - ->newAction($revision); - - $revision_submenu[] = $relationship_list->getRelationship($child_key) - ->newAction($revision); - - $curtain->addAction( - id(new PhabricatorActionView()) - ->setName(pht('Edit Related Revisions...')) - ->setIcon('fa-cog') - ->setSubmenu($revision_submenu)); + $curtain->addAction($revision_submenu); $relationship_submenu = $relationship_list->newActionMenu(); if ($relationship_submenu) { diff --git a/src/applications/maniphest/controller/ManiphestTaskDetailController.php b/src/applications/maniphest/controller/ManiphestTaskDetailController.php index df95d07c12..1a59bd2fd8 100644 --- a/src/applications/maniphest/controller/ManiphestTaskDetailController.php +++ b/src/applications/maniphest/controller/ManiphestTaskDetailController.php @@ -199,28 +199,18 @@ final class ManiphestTaskDetailController extends ManiphestController { $viewer, $task); - $parent_key = ManiphestTaskHasParentRelationship::RELATIONSHIPKEY; - $subtask_key = ManiphestTaskHasSubtaskRelationship::RELATIONSHIPKEY; - $merge_key = ManiphestTaskMergeInRelationship::RELATIONSHIPKEY; - $close_key = ManiphestTaskCloseAsDuplicateRelationship::RELATIONSHIPKEY; + $submenu_actions = array( + ManiphestTaskHasParentRelationship::RELATIONSHIPKEY, + ManiphestTaskHasSubtaskRelationship::RELATIONSHIPKEY, + ManiphestTaskMergeInRelationship::RELATIONSHIPKEY, + ManiphestTaskCloseAsDuplicateRelationship::RELATIONSHIPKEY, + ); - $task_submenu[] = $relationship_list->getRelationship($parent_key) - ->newAction($task); + $task_submenu = $relationship_list->newActionSubmenu($submenu_actions) + ->setName(pht('Edit Related Tasks...')) + ->setIcon('fa-anchor'); - $task_submenu[] = $relationship_list->getRelationship($subtask_key) - ->newAction($task); - - $task_submenu[] = $relationship_list->getRelationship($merge_key) - ->newAction($task); - - $task_submenu[] = $relationship_list->getRelationship($close_key) - ->newAction($task); - - $curtain->addAction( - id(new PhabricatorActionView()) - ->setName(pht('Edit Related Tasks...')) - ->setIcon('fa-anchor') - ->setSubmenu($task_submenu)); + $curtain->addAction($task_submenu); $relationship_submenu = $relationship_list->newActionMenu(); if ($relationship_submenu) { diff --git a/src/applications/search/controller/PhabricatorSearchBaseController.php b/src/applications/search/controller/PhabricatorSearchBaseController.php index 189048145e..d3f31c1e6a 100644 --- a/src/applications/search/controller/PhabricatorSearchBaseController.php +++ b/src/applications/search/controller/PhabricatorSearchBaseController.php @@ -2,13 +2,6 @@ abstract class PhabricatorSearchBaseController extends PhabricatorController { - - const ACTION_ATTACH = 'attach'; - const ACTION_MERGE = 'merge'; - const ACTION_DEPENDENCIES = 'dependencies'; - const ACTION_BLOCKS = 'blocks'; - const ACTION_EDGE = 'edge'; - protected function loadRelationshipObject() { $request = $this->getRequest(); $viewer = $this->getViewer(); diff --git a/src/applications/search/relationship/PhabricatorObjectRelationshipList.php b/src/applications/search/relationship/PhabricatorObjectRelationshipList.php index 46f9b6e801..31d05fa939 100644 --- a/src/applications/search/relationship/PhabricatorObjectRelationshipList.php +++ b/src/applications/search/relationship/PhabricatorObjectRelationshipList.php @@ -46,6 +46,26 @@ final class PhabricatorObjectRelationshipList extends Phobject { return $this->relationships; } + public function newActionSubmenu(array $keys) { + $object = $this->getObject(); + + $actions = array(); + + foreach ($keys as $key) { + $relationship = $this->getRelationship($key); + if (!$relationship) { + throw new Exception( + pht( + 'No object relationship of type "%s" exists.', + $key)); + } + + $actions[$key] = $relationship->newAction($object); + } + + return $this->newMenuWithActions($actions); + } + public function newActionMenu() { $relationships = $this->getRelationships(); $object = $this->getObject(); @@ -65,9 +85,22 @@ final class PhabricatorObjectRelationshipList extends Phobject { $actions = msort($actions, 'getName'); - return id(new PhabricatorActionView()) + return $this->newMenuWithActions($actions) ->setName(pht('Edit Related Objects...')) - ->setIcon('fa-link') + ->setIcon('fa-link'); + } + + private function newMenuWithActions(array $actions) { + $any_enabled = false; + foreach ($actions as $action) { + if (!$action->getDisabled()) { + $any_enabled = true; + break; + } + } + + return id(new PhabricatorActionView()) + ->setDisabled(!$any_enabled) ->setSubmenu($actions); } diff --git a/src/view/layout/PhabricatorActionView.php b/src/view/layout/PhabricatorActionView.php index 7a7cc64c3b..493f8c3dbd 100644 --- a/src/view/layout/PhabricatorActionView.php +++ b/src/view/layout/PhabricatorActionView.php @@ -84,6 +84,10 @@ final class PhabricatorActionView extends AphrontView { return $this; } + public function getDisabled() { + return $this->disabled; + } + public function setWorkflow($workflow) { $this->workflow = $workflow; return $this;