From 154234dd1f04270db12184744998f3aa25752ef0 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Thu, 31 Mar 2016 17:29:32 -0700 Subject: [PATCH] Clean up EditEngine implementation on Badges Summary: Fixes T10672. Cleaning this up myself since I was responsible for the implementation. Test Plan: Leave a comment, Edit a badge, create a badge. Reviewers: lpriestley, epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T10672 Differential Revision: https://secure.phabricator.com/D15556 --- .../PhabricatorBadgesApplication.php | 4 +-- .../PhabricatorBadgesListController.php | 13 +++------- .../PhabricatorBadgesViewController.php | 26 +++---------------- .../editor/PhabricatorBadgesEditEngine.php | 17 ++++++++++-- 4 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/applications/badges/application/PhabricatorBadgesApplication.php b/src/applications/badges/application/PhabricatorBadgesApplication.php index 0de150ee2d..5423609fda 100644 --- a/src/applications/badges/application/PhabricatorBadgesApplication.php +++ b/src/applications/badges/application/PhabricatorBadgesApplication.php @@ -45,8 +45,8 @@ final class PhabricatorBadgesApplication extends PhabricatorApplication { => 'PhabricatorBadgesEditController', 'comment/(?P[1-9]\d*)/' => 'PhabricatorBadgesCommentController', - 'edit/(?:(?P\d+)/)?' - => 'PhabricatorBadgesEditController', + $this->getEditRoutePattern('edit/') + => 'PhabricatorBadgesEditController', 'archive/(?:(?P\d+)/)?' => 'PhabricatorBadgesArchiveController', 'view/(?:(?P\d+)/)?' diff --git a/src/applications/badges/controller/PhabricatorBadgesListController.php b/src/applications/badges/controller/PhabricatorBadgesListController.php index c47f38fc5d..5c462e8341 100644 --- a/src/applications/badges/controller/PhabricatorBadgesListController.php +++ b/src/applications/badges/controller/PhabricatorBadgesListController.php @@ -16,16 +16,9 @@ final class PhabricatorBadgesListController protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); - $can_create = $this->hasApplicationCapability( - PhabricatorBadgesCreateCapability::CAPABILITY); - - $crumbs->addAction( - id(new PHUIListItemView()) - ->setName(pht('Create Badge')) - ->setHref($this->getApplicationURI('create/')) - ->setIcon('fa-plus-square') - ->setDisabled(!$can_create) - ->setWorkflow(!$can_create)); + id(new PhabricatorBadgesEditEngine()) + ->setViewer($this->getViewer()) + ->addActionToCrumbs($crumbs); return $crumbs; } diff --git a/src/applications/badges/controller/PhabricatorBadgesViewController.php b/src/applications/badges/controller/PhabricatorBadgesViewController.php index 9b61e10b44..4539440588 100644 --- a/src/applications/badges/controller/PhabricatorBadgesViewController.php +++ b/src/applications/badges/controller/PhabricatorBadgesViewController.php @@ -60,7 +60,9 @@ final class PhabricatorBadgesViewController ->setHandles($handles) ->setUser($viewer); - $add_comment = $this->buildCommentForm($badge); + $comment_view = id(new PhabricatorBadgesEditEngine()) + ->setViewer($viewer) + ->buildEditEngineCommentView($badge); $view = id(new PHUITwoColumnView()) ->setHeader($header) @@ -68,7 +70,7 @@ final class PhabricatorBadgesViewController ->setMainColumn(array( $recipient_list, $timeline, - $add_comment, + $comment_view, )) ->addPropertySection(pht('DESCRIPTION'), $details); @@ -154,24 +156,4 @@ final class PhabricatorBadgesViewController return $curtain; } - private function buildCommentForm(PhabricatorBadgesBadge $badge) { - $viewer = $this->getViewer(); - - $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); - - $add_comment_header = $is_serious - ? pht('Add Comment') - : pht('Render Honors'); - - $draft = PhabricatorDraft::newFromUserAndKey($viewer, $badge->getPHID()); - - return id(new PhabricatorApplicationTransactionCommentView()) - ->setUser($viewer) - ->setObjectPHID($badge->getPHID()) - ->setDraft($draft) - ->setHeaderText($add_comment_header) - ->setAction($this->getApplicationURI('/comment/'.$badge->getID().'/')) - ->setSubmitButtonName(pht('Add Comment')); - } - } diff --git a/src/applications/badges/editor/PhabricatorBadgesEditEngine.php b/src/applications/badges/editor/PhabricatorBadgesEditEngine.php index 28f07a6dad..8c569b5fbb 100644 --- a/src/applications/badges/editor/PhabricatorBadgesEditEngine.php +++ b/src/applications/badges/editor/PhabricatorBadgesEditEngine.php @@ -49,18 +49,31 @@ final class PhabricatorBadgesEditEngine return pht('Badge'); } + protected function getObjectCreateCancelURI($object) { + return $this->getApplication()->getApplicationURI('/'); + } + + protected function getEditorURI() { + return $this->getApplication()->getApplicationURI('edit/'); + } + protected function getCommentViewHeaderText($object) { - return pht('Add Comment'); + return pht('Render Honors'); } protected function getCommentViewButtonText($object) { - return pht('Submit'); + return pht('Salute'); } protected function getObjectViewURI($object) { return $object->getViewURI(); } + protected function getCreateNewObjectPolicy() { + return $this->getApplication()->getPolicy( + PhabricatorBadgesCreateCapability::CAPABILITY); + } + protected function buildCustomEditFields($object) { return array(