Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14014064
D14771.id35712.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
11 KB
Referenced Files
None
Subscribers
None
D14771.id35712.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1762,6 +1762,7 @@
'PhabricatorBadgesDAO' => 'applications/badges/storage/PhabricatorBadgesDAO.php',
'PhabricatorBadgesDefaultEditCapability' => 'applications/badges/capability/PhabricatorBadgesDefaultEditCapability.php',
'PhabricatorBadgesEditController' => 'applications/badges/controller/PhabricatorBadgesEditController.php',
+ 'PhabricatorBadgesEditEngine' => 'applications/badges/editor/PhabricatorBadgesEditEngine.php',
'PhabricatorBadgesEditIconController' => 'applications/badges/controller/PhabricatorBadgesEditIconController.php',
'PhabricatorBadgesEditRecipientsController' => 'applications/badges/controller/PhabricatorBadgesEditRecipientsController.php',
'PhabricatorBadgesEditor' => 'applications/badges/editor/PhabricatorBadgesEditor.php',
@@ -5831,7 +5832,8 @@
'PhabricatorBadgesCreateCapability' => 'PhabricatorPolicyCapability',
'PhabricatorBadgesDAO' => 'PhabricatorLiskDAO',
'PhabricatorBadgesDefaultEditCapability' => 'PhabricatorPolicyCapability',
- 'PhabricatorBadgesEditController' => 'PhabricatorBadgesController',
+ 'PhabricatorBadgesEditController' => 'PhabricatorPasteController',
+ 'PhabricatorBadgesEditEngine' => 'PhabricatorEditEngine',
'PhabricatorBadgesEditIconController' => 'PhabricatorBadgesController',
'PhabricatorBadgesEditRecipientsController' => 'PhabricatorBadgesController',
'PhabricatorBadgesEditor' => 'PhabricatorApplicationTransactionEditor',
diff --git a/src/applications/badges/controller/PhabricatorBadgesEditController.php b/src/applications/badges/controller/PhabricatorBadgesEditController.php
--- a/src/applications/badges/controller/PhabricatorBadgesEditController.php
+++ b/src/applications/badges/controller/PhabricatorBadgesEditController.php
@@ -1,195 +1,11 @@
<?php
-final class PhabricatorBadgesEditController
- extends PhabricatorBadgesController {
+final class PhabricatorBadgesEditController extends PhabricatorPasteController {
public function handleRequest(AphrontRequest $request) {
- $viewer = $request->getViewer();
- $id = $request->getURIData('id');
-
- if ($id) {
- $badge = id(new PhabricatorBadgesQuery())
- ->setViewer($viewer)
- ->withIDs(array($id))
- ->requireCapabilities(
- array(
- PhabricatorPolicyCapability::CAN_VIEW,
- PhabricatorPolicyCapability::CAN_EDIT,
- ))
- ->executeOne();
- if (!$badge) {
- return new Aphront404Response();
- }
- $is_new = false;
- } else {
- $this->requireApplicationCapability(
- PhabricatorBadgesCreateCapability::CAPABILITY);
-
- $badge = PhabricatorBadgesBadge::initializeNewBadge($viewer);
- $is_new = true;
- }
-
- if ($is_new) {
- $title = pht('Create Badge');
- $button_text = pht('Create Badge');
- $cancel_uri = $this->getApplicationURI();
- } else {
- $title = pht(
- 'Edit %s',
- $badge->getName());
- $button_text = pht('Save Changes');
- $cancel_uri = $this->getApplicationURI('view/'.$id.'/');
- }
-
- $e_name = true;
- $v_name = $badge->getName();
- $v_icon = $badge->getIcon();
- $v_flav = $badge->getFlavor();
- $v_desc = $badge->getDescription();
- $v_qual = $badge->getQuality();
- $v_edit = $badge->getEditPolicy();
-
- $validation_exception = null;
- if ($request->isFormPost()) {
- $v_name = $request->getStr('name');
- $v_flav = $request->getStr('flavor');
- $v_desc = $request->getStr('description');
- $v_icon = $request->getStr('icon');
- $v_qual = $request->getStr('quality');
-
- $v_view = $request->getStr('viewPolicy');
- $v_edit = $request->getStr('editPolicy');
-
- $type_name = PhabricatorBadgesTransaction::TYPE_NAME;
- $type_flav = PhabricatorBadgesTransaction::TYPE_FLAVOR;
- $type_desc = PhabricatorBadgesTransaction::TYPE_DESCRIPTION;
- $type_icon = PhabricatorBadgesTransaction::TYPE_ICON;
- $type_qual = PhabricatorBadgesTransaction::TYPE_QUALITY;
-
- $type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY;
-
- $xactions = array();
-
- $xactions[] = id(new PhabricatorBadgesTransaction())
- ->setTransactionType($type_name)
- ->setNewValue($v_name);
-
- $xactions[] = id(new PhabricatorBadgesTransaction())
- ->setTransactionType($type_flav)
- ->setNewValue($v_flav);
-
- $xactions[] = id(new PhabricatorBadgesTransaction())
- ->setTransactionType($type_desc)
- ->setNewValue($v_desc);
-
- $xactions[] = id(new PhabricatorBadgesTransaction())
- ->setTransactionType($type_icon)
- ->setNewValue($v_icon);
-
- $xactions[] = id(new PhabricatorBadgesTransaction())
- ->setTransactionType($type_qual)
- ->setNewValue($v_qual);
-
- $xactions[] = id(new PhabricatorBadgesTransaction())
- ->setTransactionType($type_edit)
- ->setNewValue($v_edit);
-
- $editor = id(new PhabricatorBadgesEditor())
- ->setActor($viewer)
- ->setContentSourceFromRequest($request)
- ->setContinueOnNoEffect(true);
-
- try {
- $editor->applyTransactions($badge, $xactions);
- $return_uri = $this->getApplicationURI('view/'.$badge->getID().'/');
- return id(new AphrontRedirectResponse())->setURI($return_uri);
-
- } catch (PhabricatorApplicationTransactionValidationException $ex) {
- $validation_exception = $ex;
-
- $e_name = $ex->getShortMessage($type_name);
- }
- }
-
- if ($is_new) {
- $icon_uri = $this->getApplicationURI('icon/');
- } else {
- $icon_uri = $this->getApplicationURI('icon/'.$badge->getID().'/');
- }
- $icon_display = PhabricatorBadgesIcon::renderIconForChooser($v_icon);
-
- $policies = id(new PhabricatorPolicyQuery())
- ->setViewer($viewer)
- ->setObject($badge)
- ->execute();
-
- $form = id(new AphrontFormView())
- ->setUser($viewer)
- ->appendChild(
- id(new AphrontFormTextControl())
- ->setName('name')
- ->setLabel(pht('Name'))
- ->setValue($v_name)
- ->setError($e_name))
- ->appendChild(
- id(new AphrontFormTextControl())
- ->setName('flavor')
- ->setLabel(pht('Flavor Text'))
- ->setValue($v_flav))
- ->appendChild(
- id(new AphrontFormChooseButtonControl())
- ->setLabel(pht('Icon'))
- ->setName('icon')
- ->setDisplayValue($icon_display)
- ->setButtonText(pht('Choose Icon...'))
- ->setChooseURI($icon_uri)
- ->setValue($v_icon))
- ->appendChild(
- id(new AphrontFormSelectControl())
- ->setName('quality')
- ->setLabel(pht('Quality'))
- ->setValue($v_qual)
- ->setOptions($badge->getQualityNameMap()))
- ->appendChild(
- id(new PhabricatorRemarkupControl())
- ->setUser($viewer)
- ->setName('description')
- ->setLabel(pht('Description'))
- ->setValue($v_desc))
- ->appendChild(
- id(new AphrontFormPolicyControl())
- ->setName('editPolicy')
- ->setPolicyObject($badge)
- ->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
- ->setValue($v_edit)
- ->setPolicies($policies))
- ->appendChild(
- id(new AphrontFormSubmitControl())
- ->setValue($button_text)
- ->addCancelButton($cancel_uri));
-
- $crumbs = $this->buildApplicationCrumbs();
- if ($is_new) {
- $crumbs->addTextCrumb(pht('Create Badge'));
- } else {
- $crumbs->addTextCrumb(
- $badge->getName(),
- '/badges/view/'.$badge->getID().'/');
- $crumbs->addTextCrumb(pht('Edit'));
- }
-
- $box = id(new PHUIObjectBoxView())
- ->setValidationException($validation_exception)
- ->setHeaderText($title)
- ->appendChild($form);
-
- return $this->newPage()
- ->setTitle($title)
- ->setCrumbs($crumbs)
- ->appendChild(
- array(
- $box,
- ));
+ return id(new PhabricatorBadgesEditEngine())
+ ->setController($this)
+ ->buildResponse();
}
}
diff --git a/src/applications/badges/editor/PhabricatorBadgesEditEngine.php b/src/applications/badges/editor/PhabricatorBadgesEditEngine.php
new file mode 100644
--- /dev/null
+++ b/src/applications/badges/editor/PhabricatorBadgesEditEngine.php
@@ -0,0 +1,99 @@
+<?php
+
+final class PhabricatorBadgesEditEngine
+ extends PhabricatorEditEngine {
+
+ const ENGINECONST = 'badges.badge';
+
+ public function getEngineName() {
+ return pht('Blogs');
+ }
+
+ public function getEngineApplicationClass() {
+ return 'PhabricatorBadgesApplication';
+ }
+
+ protected function newEditableObject() {
+ return PhabricatorBadgesBadge::initializeNewBadge($this->getViewer());
+ }
+
+ protected function newObjectQuery() {
+ return new PhabricatorBadgesQuery();
+ }
+
+ protected function getObjectCreateTitleText($object) {
+ return pht('Create New Badge');
+ }
+
+ protected function getObjectEditTitleText($object) {
+ return pht('Edit %s', $object->getName());
+ }
+
+ protected function getObjectEditShortText($object) {
+ return $object->getName();
+ }
+
+ protected function getObjectCreateShortText() {
+ return pht('Create Badge');
+ }
+
+ protected function getCommentViewHeaderText($object) {
+ return pht('Add Comment');
+ }
+
+ protected function getCommentViewButtonText($object) {
+ return pht('Submit');
+ }
+
+ protected function getObjectViewURI($object) {
+ return $object->getViewURI();
+ }
+
+ protected function buildCustomEditFields($object) {
+
+ $is_new = true;
+ if ($is_new) {
+ $icon_uri = '/badges/icon/';
+ } else {
+ $icon_uri = '/badges/icon/'.$object->getID().'/';
+ }
+ $icon_display = PhabricatorBadgesIcon::renderIconForChooser(
+ $object->getIcon());
+
+ return array(
+ id(new PhabricatorTextEditField())
+ ->setKey('name')
+ ->setLabel(pht('Name'))
+ ->setDescription(pht('Badge name.'))
+ ->setTransactionType(PhabricatorBadgesTransaction::TYPE_NAME)
+ ->setValue($object->getName()),
+ id(new PhabricatorTextEditField())
+ ->setKey('flavor')
+ ->setLabel(pht('Flavor text'))
+ ->setDescription(pht('Short description of the badge.'))
+ ->setValue($object->getFlavor())
+ ->setTransactionType(PhabricatorBadgesTransaction::TYPE_FLAVOR),
+ id(new AphrontFormChooseButtonControl())
+ ->setKey('icon')
+ ->setLabel(pht('Icon'))
+ ->setDisplayValue($icon_display)
+ ->setButtonText(pht('Choose Icon...'))
+ ->setChooseURI($icon_uri)
+ ->setTransactionType(PhabricatorBadgesTransaction::TYPE_ICON)
+ ->setValue($object->getIcon()),
+ id(new PhabricatorSelectEditField())
+ ->setKey('quality')
+ ->setLabel(pht('Quality'))
+ ->setValue($object->getQuality())
+ ->setTransactionType(PhabricatorBadgesTransaction::TYPE_QUALITY)
+ ->setOptions($object->getQualityNameMap()),
+ id(new PhabricatorRemarkupEditField())
+ ->setKey('description')
+ ->setLabel(pht('Description'))
+ ->setDescription(pht('Badge long description.'))
+ ->setTransactionType(PhabricatorBadgesTransaction::TYPE_DESCRIPTION)
+ ->setValue($object->getDescription()),
+ );
+ }
+
+}
diff --git a/src/applications/badges/storage/PhabricatorBadgesBadge.php b/src/applications/badges/storage/PhabricatorBadgesBadge.php
--- a/src/applications/badges/storage/PhabricatorBadgesBadge.php
+++ b/src/applications/badges/storage/PhabricatorBadgesBadge.php
@@ -115,6 +115,10 @@
return $this->assertAttached($this->recipientPHIDs);
}
+ public function getViewURI() {
+ return $this->getApplicationURI('view/'.$this->getID().'/');
+ }
+
public function save() {
if (!$this->getMailKey()) {
$this->setMailKey(Filesystem::readRandomCharacters(20));
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 3, 9:42 PM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6739583
Default Alt Text
D14771.id35712.diff (11 KB)
Attached To
Mode
D14771: Convert Badges to use EditEngine
Attached
Detach File
Event Timeline
Log In to Comment