@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.

Convert Badges to use EditEngine

Summary: Moves Badges over to EditEngine

Test Plan: Create a new Badge, Edit a Badge

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

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

authored by

Chad Little and committed by
chad
45ccc930 fe6224f5

+109 -180
+3 -1
src/__phutil_library_map__.php
··· 1783 1783 'PhabricatorBadgesDAO' => 'applications/badges/storage/PhabricatorBadgesDAO.php', 1784 1784 'PhabricatorBadgesDefaultEditCapability' => 'applications/badges/capability/PhabricatorBadgesDefaultEditCapability.php', 1785 1785 'PhabricatorBadgesEditController' => 'applications/badges/controller/PhabricatorBadgesEditController.php', 1786 + 'PhabricatorBadgesEditEngine' => 'applications/badges/editor/PhabricatorBadgesEditEngine.php', 1786 1787 'PhabricatorBadgesEditRecipientsController' => 'applications/badges/controller/PhabricatorBadgesEditRecipientsController.php', 1787 1788 'PhabricatorBadgesEditor' => 'applications/badges/editor/PhabricatorBadgesEditor.php', 1788 1789 'PhabricatorBadgesIconSet' => 'applications/badges/icon/PhabricatorBadgesIconSet.php', ··· 5945 5946 'PhabricatorBadgesCreateCapability' => 'PhabricatorPolicyCapability', 5946 5947 'PhabricatorBadgesDAO' => 'PhabricatorLiskDAO', 5947 5948 'PhabricatorBadgesDefaultEditCapability' => 'PhabricatorPolicyCapability', 5948 - 'PhabricatorBadgesEditController' => 'PhabricatorBadgesController', 5949 + 'PhabricatorBadgesEditController' => 'PhabricatorPasteController', 5950 + 'PhabricatorBadgesEditEngine' => 'PhabricatorEditEngine', 5949 5951 'PhabricatorBadgesEditRecipientsController' => 'PhabricatorBadgesController', 5950 5952 'PhabricatorBadgesEditor' => 'PhabricatorApplicationTransactionEditor', 5951 5953 'PhabricatorBadgesIconSet' => 'PhabricatorIconSet',
+4 -179
src/applications/badges/controller/PhabricatorBadgesEditController.php
··· 1 1 <?php 2 2 3 - final class PhabricatorBadgesEditController 4 - extends PhabricatorBadgesController { 3 + final class PhabricatorBadgesEditController extends PhabricatorPasteController { 5 4 6 5 public function handleRequest(AphrontRequest $request) { 7 - $viewer = $request->getViewer(); 8 - $id = $request->getURIData('id'); 9 - 10 - if ($id) { 11 - $badge = id(new PhabricatorBadgesQuery()) 12 - ->setViewer($viewer) 13 - ->withIDs(array($id)) 14 - ->requireCapabilities( 15 - array( 16 - PhabricatorPolicyCapability::CAN_VIEW, 17 - PhabricatorPolicyCapability::CAN_EDIT, 18 - )) 19 - ->executeOne(); 20 - if (!$badge) { 21 - return new Aphront404Response(); 22 - } 23 - $is_new = false; 24 - } else { 25 - $this->requireApplicationCapability( 26 - PhabricatorBadgesCreateCapability::CAPABILITY); 27 - 28 - $badge = PhabricatorBadgesBadge::initializeNewBadge($viewer); 29 - $is_new = true; 30 - } 31 - 32 - if ($is_new) { 33 - $title = pht('Create Badge'); 34 - $button_text = pht('Create Badge'); 35 - $cancel_uri = $this->getApplicationURI(); 36 - } else { 37 - $title = pht( 38 - 'Edit %s', 39 - $badge->getName()); 40 - $button_text = pht('Save Changes'); 41 - $cancel_uri = $this->getApplicationURI('view/'.$id.'/'); 42 - } 43 - 44 - $e_name = true; 45 - $v_name = $badge->getName(); 46 - $v_icon = $badge->getIcon(); 47 - $v_flav = $badge->getFlavor(); 48 - $v_desc = $badge->getDescription(); 49 - $v_qual = $badge->getQuality(); 50 - $v_edit = $badge->getEditPolicy(); 51 - 52 - $validation_exception = null; 53 - if ($request->isFormPost()) { 54 - $v_name = $request->getStr('name'); 55 - $v_flav = $request->getStr('flavor'); 56 - $v_desc = $request->getStr('description'); 57 - $v_icon = $request->getStr('icon'); 58 - $v_qual = $request->getStr('quality'); 59 - 60 - $v_view = $request->getStr('viewPolicy'); 61 - $v_edit = $request->getStr('editPolicy'); 62 - 63 - $type_name = PhabricatorBadgesTransaction::TYPE_NAME; 64 - $type_flav = PhabricatorBadgesTransaction::TYPE_FLAVOR; 65 - $type_desc = PhabricatorBadgesTransaction::TYPE_DESCRIPTION; 66 - $type_icon = PhabricatorBadgesTransaction::TYPE_ICON; 67 - $type_qual = PhabricatorBadgesTransaction::TYPE_QUALITY; 68 - 69 - $type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY; 70 - 71 - $xactions = array(); 72 - 73 - $xactions[] = id(new PhabricatorBadgesTransaction()) 74 - ->setTransactionType($type_name) 75 - ->setNewValue($v_name); 76 - 77 - $xactions[] = id(new PhabricatorBadgesTransaction()) 78 - ->setTransactionType($type_flav) 79 - ->setNewValue($v_flav); 80 - 81 - $xactions[] = id(new PhabricatorBadgesTransaction()) 82 - ->setTransactionType($type_desc) 83 - ->setNewValue($v_desc); 84 - 85 - $xactions[] = id(new PhabricatorBadgesTransaction()) 86 - ->setTransactionType($type_icon) 87 - ->setNewValue($v_icon); 88 - 89 - $xactions[] = id(new PhabricatorBadgesTransaction()) 90 - ->setTransactionType($type_qual) 91 - ->setNewValue($v_qual); 92 - 93 - $xactions[] = id(new PhabricatorBadgesTransaction()) 94 - ->setTransactionType($type_edit) 95 - ->setNewValue($v_edit); 96 - 97 - $editor = id(new PhabricatorBadgesEditor()) 98 - ->setActor($viewer) 99 - ->setContentSourceFromRequest($request) 100 - ->setContinueOnNoEffect(true); 101 - 102 - try { 103 - $editor->applyTransactions($badge, $xactions); 104 - $return_uri = $this->getApplicationURI('view/'.$badge->getID().'/'); 105 - return id(new AphrontRedirectResponse())->setURI($return_uri); 106 - 107 - } catch (PhabricatorApplicationTransactionValidationException $ex) { 108 - $validation_exception = $ex; 109 - 110 - $e_name = $ex->getShortMessage($type_name); 111 - } 112 - } 113 - 114 - $policies = id(new PhabricatorPolicyQuery()) 115 - ->setViewer($viewer) 116 - ->setObject($badge) 117 - ->execute(); 118 - 119 - $form = id(new AphrontFormView()) 120 - ->setUser($viewer) 121 - ->appendChild( 122 - id(new AphrontFormTextControl()) 123 - ->setName('name') 124 - ->setLabel(pht('Name')) 125 - ->setValue($v_name) 126 - ->setError($e_name)) 127 - ->appendChild( 128 - id(new AphrontFormTextControl()) 129 - ->setName('flavor') 130 - ->setLabel(pht('Flavor Text')) 131 - ->setValue($v_flav)) 132 - ->appendChild( 133 - id(new PHUIFormIconSetControl()) 134 - ->setLabel(pht('Icon')) 135 - ->setName('icon') 136 - ->setIconSet(new PhabricatorBadgesIconSet()) 137 - ->setValue($v_icon)) 138 - ->appendChild( 139 - id(new AphrontFormSelectControl()) 140 - ->setName('quality') 141 - ->setLabel(pht('Quality')) 142 - ->setValue($v_qual) 143 - ->setOptions($badge->getQualityNameMap())) 144 - ->appendChild( 145 - id(new PhabricatorRemarkupControl()) 146 - ->setUser($viewer) 147 - ->setName('description') 148 - ->setLabel(pht('Description')) 149 - ->setValue($v_desc)) 150 - ->appendChild( 151 - id(new AphrontFormPolicyControl()) 152 - ->setName('editPolicy') 153 - ->setPolicyObject($badge) 154 - ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) 155 - ->setValue($v_edit) 156 - ->setPolicies($policies)) 157 - ->appendChild( 158 - id(new AphrontFormSubmitControl()) 159 - ->setValue($button_text) 160 - ->addCancelButton($cancel_uri)); 161 - 162 - $crumbs = $this->buildApplicationCrumbs(); 163 - if ($is_new) { 164 - $crumbs->addTextCrumb(pht('Create Badge')); 165 - } else { 166 - $crumbs->addTextCrumb( 167 - $badge->getName(), 168 - '/badges/view/'.$badge->getID().'/'); 169 - $crumbs->addTextCrumb(pht('Edit')); 170 - } 171 - 172 - $box = id(new PHUIObjectBoxView()) 173 - ->setValidationException($validation_exception) 174 - ->setHeaderText($title) 175 - ->appendChild($form); 176 - 177 - return $this->newPage() 178 - ->setTitle($title) 179 - ->setCrumbs($crumbs) 180 - ->appendChild( 181 - array( 182 - $box, 183 - )); 6 + return id(new PhabricatorBadgesEditEngine()) 7 + ->setController($this) 8 + ->buildResponse(); 184 9 } 185 10 186 11 }
+98
src/applications/badges/editor/PhabricatorBadgesEditEngine.php
··· 1 + <?php 2 + 3 + final class PhabricatorBadgesEditEngine 4 + extends PhabricatorEditEngine { 5 + 6 + const ENGINECONST = 'badges.badge'; 7 + 8 + public function getEngineName() { 9 + return pht('Badges'); 10 + } 11 + 12 + public function getEngineApplicationClass() { 13 + return 'PhabricatorBadgesApplication'; 14 + } 15 + 16 + public function getSummaryHeader() { 17 + return pht('Configure Badges Forms'); 18 + } 19 + 20 + public function getSummaryText() { 21 + return pht('Configure creation and editing forms in Badges.'); 22 + } 23 + 24 + protected function newEditableObject() { 25 + return PhabricatorBadgesBadge::initializeNewBadge($this->getViewer()); 26 + } 27 + 28 + protected function newObjectQuery() { 29 + return new PhabricatorBadgesQuery(); 30 + } 31 + 32 + protected function getObjectCreateTitleText($object) { 33 + return pht('Create New Badge'); 34 + } 35 + 36 + protected function getObjectEditTitleText($object) { 37 + return pht('Edit %s', $object->getName()); 38 + } 39 + 40 + protected function getObjectEditShortText($object) { 41 + return $object->getName(); 42 + } 43 + 44 + protected function getObjectCreateShortText() { 45 + return pht('Create Badge'); 46 + } 47 + 48 + protected function getCommentViewHeaderText($object) { 49 + return pht('Add Comment'); 50 + } 51 + 52 + protected function getCommentViewButtonText($object) { 53 + return pht('Submit'); 54 + } 55 + 56 + protected function getObjectViewURI($object) { 57 + return $object->getViewURI(); 58 + } 59 + 60 + protected function buildCustomEditFields($object) { 61 + 62 + return array( 63 + id(new PhabricatorTextEditField()) 64 + ->setKey('name') 65 + ->setLabel(pht('Name')) 66 + ->setDescription(pht('Badge name.')) 67 + ->setTransactionType(PhabricatorBadgesTransaction::TYPE_NAME) 68 + ->setValue($object->getName()), 69 + id(new PhabricatorTextEditField()) 70 + ->setKey('flavor') 71 + ->setLabel(pht('Flavor text')) 72 + ->setDescription(pht('Short description of the badge.')) 73 + ->setValue($object->getFlavor()) 74 + ->setTransactionType(PhabricatorBadgesTransaction::TYPE_FLAVOR), 75 + id(new PhabricatorIconSetEditField()) 76 + ->setKey('icon') 77 + ->setLabel(pht('Icon')) 78 + ->setIconSet(new PhabricatorBadgesIconSet()) 79 + ->setTransactionType(PhabricatorBadgesTransaction::TYPE_ICON) 80 + ->setConduitDescription(pht('Change the badge icon.')) 81 + ->setConduitTypeDescription(pht('New badge icon.')) 82 + ->setValue($object->getIcon()), 83 + id(new PhabricatorSelectEditField()) 84 + ->setKey('quality') 85 + ->setLabel(pht('Quality')) 86 + ->setValue($object->getQuality()) 87 + ->setTransactionType(PhabricatorBadgesTransaction::TYPE_QUALITY) 88 + ->setOptions($object->getQualityNameMap()), 89 + id(new PhabricatorRemarkupEditField()) 90 + ->setKey('description') 91 + ->setLabel(pht('Description')) 92 + ->setDescription(pht('Badge long description.')) 93 + ->setTransactionType(PhabricatorBadgesTransaction::TYPE_DESCRIPTION) 94 + ->setValue($object->getDescription()), 95 + ); 96 + } 97 + 98 + }
+4
src/applications/badges/storage/PhabricatorBadgesBadge.php
··· 111 111 return $this->assertAttached($this->recipientPHIDs); 112 112 } 113 113 114 + public function getViewURI() { 115 + return '/badges/view/'.$this->getID().'/'; 116 + } 117 + 114 118 public function save() { 115 119 if (!$this->getMailKey()) { 116 120 $this->setMailKey(Filesystem::readRandomCharacters(20));