Page MenuHomePhabricator

D16573.id.diff
No OneTemporary

D16573.id.diff

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
@@ -3184,6 +3184,7 @@
'PhabricatorPhurlURLCommentController' => 'applications/phurl/controller/PhabricatorPhurlURLCommentController.php',
'PhabricatorPhurlURLCreateCapability' => 'applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php',
'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php',
+ 'PhabricatorPhurlURLEditEngine' => 'applications/phurl/editor/PhabricatorPhurlURLEditEngine.php',
'PhabricatorPhurlURLEditor' => 'applications/phurl/editor/PhabricatorPhurlURLEditor.php',
'PhabricatorPhurlURLListController' => 'applications/phurl/controller/PhabricatorPhurlURLListController.php',
'PhabricatorPhurlURLMailReceiver' => 'applications/phurl/mail/PhabricatorPhurlURLMailReceiver.php',
@@ -8097,6 +8098,7 @@
'PhabricatorPhurlURLCommentController' => 'PhabricatorPhurlController',
'PhabricatorPhurlURLCreateCapability' => 'PhabricatorPolicyCapability',
'PhabricatorPhurlURLEditController' => 'PhabricatorPhurlController',
+ 'PhabricatorPhurlURLEditEngine' => 'PhabricatorEditEngine',
'PhabricatorPhurlURLEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorPhurlURLListController' => 'PhabricatorPhurlController',
'PhabricatorPhurlURLMailReceiver' => 'PhabricatorObjectMailReceiver',
diff --git a/src/applications/paste/application/PhabricatorPasteApplication.php b/src/applications/paste/application/PhabricatorPasteApplication.php
--- a/src/applications/paste/application/PhabricatorPasteApplication.php
+++ b/src/applications/paste/application/PhabricatorPasteApplication.php
@@ -38,7 +38,6 @@
=> 'PhabricatorPasteViewController',
'/paste/' => array(
'(query/(?P<queryKey>[^/]+)/)?' => 'PhabricatorPasteListController',
- 'create/' => 'PhabricatorPasteEditController',
$this->getEditRoutePattern('edit/') => 'PhabricatorPasteEditController',
'raw/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteRawController',
'archive/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteArchiveController',
diff --git a/src/applications/phurl/application/PhabricatorPhurlApplication.php b/src/applications/phurl/application/PhabricatorPhurlApplication.php
--- a/src/applications/phurl/application/PhabricatorPhurlApplication.php
+++ b/src/applications/phurl/application/PhabricatorPhurlApplication.php
@@ -46,9 +46,7 @@
'(?:query/(?P<queryKey>[^/]+)/)?'
=> 'PhabricatorPhurlURLListController',
'url/' => array(
- 'create/'
- => 'PhabricatorPhurlURLEditController',
- 'edit/(?P<id>[1-9]\d*)/'
+ $this->getEditRoutePattern('edit/')
=> 'PhabricatorPhurlURLEditController',
'comment/(?P<id>[1-9]\d*)/'
=> 'PhabricatorPhurlURLCommentController',
diff --git a/src/applications/phurl/controller/PhabricatorPhurlController.php b/src/applications/phurl/controller/PhabricatorPhurlController.php
--- a/src/applications/phurl/controller/PhabricatorPhurlController.php
+++ b/src/applications/phurl/controller/PhabricatorPhurlController.php
@@ -3,17 +3,10 @@
abstract class PhabricatorPhurlController extends PhabricatorController {
protected function buildApplicationCrumbs() {
- $can_create = $this->hasApplicationCapability(
- PhabricatorPhurlURLCreateCapability::CAPABILITY);
-
$crumbs = parent::buildApplicationCrumbs();
- $crumbs->addAction(
- id(new PHUIListItemView())
- ->setName(pht('Shorten URL'))
- ->setHref($this->getApplicationURI().'url/create/')
- ->setIcon('fa-plus-square')
- ->setDisabled(!$can_create)
- ->setWorkflow(!$can_create));
+ id(new PhabricatorPhurlURLEditEngine())
+ ->setViewer($this->getViewer())
+ ->addActionToCrumbs($crumbs);
return $crumbs;
}
diff --git a/src/applications/phurl/controller/PhabricatorPhurlURLEditController.php b/src/applications/phurl/controller/PhabricatorPhurlURLEditController.php
--- a/src/applications/phurl/controller/PhabricatorPhurlURLEditController.php
+++ b/src/applications/phurl/controller/PhabricatorPhurlURLEditController.php
@@ -4,263 +4,8 @@
extends PhabricatorPhurlController {
public function handleRequest(AphrontRequest $request) {
- $id = $request->getURIData('id');
- $is_create = !$id;
-
- $viewer = $this->getViewer();
- $user_phid = $viewer->getPHID();
- $error_long_url = true;
- $error_alias = null;
- $validation_exception = null;
-
- $next_workflow = $request->getStr('next');
- $uri_query = $request->getStr('query');
-
- if ($is_create) {
- $this->requireApplicationCapability(
- PhabricatorPhurlURLCreateCapability::CAPABILITY);
-
- $url = PhabricatorPhurlURL::initializeNewPhurlURL(
- $viewer);
- $submit_label = pht('Create');
- $page_title = pht('Shorten URL');
- $header_icon = 'fa-plus-square';
- $subscribers = array();
- $cancel_uri = $this->getApplicationURI();
- } else {
- $url = id(new PhabricatorPhurlURLQuery())
- ->setViewer($viewer)
- ->withIDs(array($id))
- ->requireCapabilities(
- array(
- PhabricatorPolicyCapability::CAN_VIEW,
- PhabricatorPolicyCapability::CAN_EDIT,
- ))
- ->executeOne();
-
- if (!$url) {
- return new Aphront404Response();
- }
-
- $submit_label = pht('Update');
- $page_title = pht('Edit URL: %s', $url->getName());
- $header_icon = 'fa-pencil';
-
- $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID(
- $url->getPHID());
-
- $cancel_uri = '/U'.$url->getID();
- }
-
- if ($is_create) {
- $projects = array();
- } else {
- $projects = PhabricatorEdgeQuery::loadDestinationPHIDs(
- $url->getPHID(),
- PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
- $projects = array_reverse($projects);
- }
-
- $name = $url->getName();
- $long_url = $url->getLongURL();
- $alias = $url->getAlias();
- $description = $url->getDescription();
- $edit_policy = $url->getEditPolicy();
- $view_policy = $url->getViewPolicy();
- $space = $url->getSpacePHID();
-
- if ($request->isFormPost()) {
- $xactions = array();
- $name = $request->getStr('name');
- $long_url = $request->getStr('longURL');
- $alias = $request->getStr('alias');
- $projects = $request->getArr('projects');
- $description = $request->getStr('description');
- $subscribers = $request->getArr('subscribers');
- $edit_policy = $request->getStr('editPolicy');
- $view_policy = $request->getStr('viewPolicy');
- $space = $request->getStr('spacePHID');
-
- $xactions[] = id(new PhabricatorPhurlURLTransaction())
- ->setTransactionType(
- PhabricatorPhurlURLTransaction::TYPE_NAME)
- ->setNewValue($name);
-
- $xactions[] = id(new PhabricatorPhurlURLTransaction())
- ->setTransactionType(
- PhabricatorPhurlURLTransaction::TYPE_URL)
- ->setNewValue($long_url);
-
- $xactions[] = id(new PhabricatorPhurlURLTransaction())
- ->setTransactionType(
- PhabricatorPhurlURLTransaction::TYPE_ALIAS)
- ->setNewValue($alias);
-
- $xactions[] = id(new PhabricatorPhurlURLTransaction())
- ->setTransactionType(
- PhabricatorTransactions::TYPE_SUBSCRIBERS)
- ->setNewValue(array('=' => array_fuse($subscribers)));
-
- $xactions[] = id(new PhabricatorPhurlURLTransaction())
- ->setTransactionType(
- PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION)
- ->setNewValue($description);
-
- $xactions[] = id(new PhabricatorPhurlURLTransaction())
- ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
- ->setNewValue($view_policy);
-
- $xactions[] = id(new PhabricatorPhurlURLTransaction())
- ->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)
- ->setNewValue($edit_policy);
-
- $xactions[] = id(new PhabricatorPhurlURLTransaction())
- ->setTransactionType(PhabricatorTransactions::TYPE_SPACE)
- ->setNewValue($space);
-
- $editor = id(new PhabricatorPhurlURLEditor())
- ->setActor($viewer)
- ->setContentSourceFromRequest($request)
- ->setContinueOnNoEffect(true);
-
- try {
- $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
- $xactions[] = id(new PhabricatorPhurlURLTransaction())
- ->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
- ->setMetadataValue('edge:type', $proj_edge_type)
- ->setNewValue(array('=' => array_fuse($projects)));
-
- $xactions = $editor->applyTransactions($url, $xactions);
- return id(new AphrontRedirectResponse())
- ->setURI($url->getURI());
- } catch (PhabricatorApplicationTransactionValidationException $ex) {
- $validation_exception = $ex;
- $error_long_url = $ex->getShortMessage(
- PhabricatorPhurlURLTransaction::TYPE_URL);
- $error_alias = $ex->getShortMessage(
- PhabricatorPhurlURLTransaction::TYPE_ALIAS);
- }
- }
-
- $current_policies = id(new PhabricatorPolicyQuery())
- ->setViewer($viewer)
- ->setObject($url)
- ->execute();
-
- $name = id(new AphrontFormTextControl())
- ->setLabel(pht('Name'))
- ->setName('name')
- ->setValue($name);
-
- $long_url = id(new AphrontFormTextControl())
- ->setLabel(pht('URL'))
- ->setName('longURL')
- ->setValue($long_url)
- ->setError($error_long_url);
-
- $alias = id(new AphrontFormTextControl())
- ->setLabel(pht('Alias'))
- ->setName('alias')
- ->setValue($alias)
- ->setError($error_alias);
-
- $projects = id(new AphrontFormTokenizerControl())
- ->setLabel(pht('Tags'))
- ->setName('projects')
- ->setValue($projects)
- ->setUser($viewer)
- ->setDatasource(new PhabricatorProjectDatasource());
-
- $description = id(new PhabricatorRemarkupControl())
- ->setLabel(pht('Description'))
- ->setName('description')
- ->setValue($description)
- ->setUser($viewer);
-
- $view_policies = id(new AphrontFormPolicyControl())
- ->setUser($viewer)
- ->setValue($view_policy)
- ->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
- ->setPolicyObject($url)
- ->setPolicies($current_policies)
- ->setSpacePHID($space)
- ->setName('viewPolicy');
- $edit_policies = id(new AphrontFormPolicyControl())
- ->setUser($viewer)
- ->setValue($edit_policy)
- ->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
- ->setPolicyObject($url)
- ->setPolicies($current_policies)
- ->setName('editPolicy');
-
- $subscribers = id(new AphrontFormTokenizerControl())
- ->setLabel(pht('Subscribers'))
- ->setName('subscribers')
- ->setValue($subscribers)
- ->setUser($viewer)
- ->setDatasource(new PhabricatorMetaMTAMailableDatasource());
-
- $form = id(new AphrontFormView())
- ->setUser($viewer)
- ->appendChild($name)
- ->appendChild($long_url)
- ->appendChild($alias)
- ->appendControl($view_policies)
- ->appendControl($edit_policies)
- ->appendControl($subscribers)
- ->appendChild($projects)
- ->appendChild($description);
-
-
- if ($request->isAjax()) {
- return $this->newDialog()
- ->setTitle($page_title)
- ->setWidth(AphrontDialogView::WIDTH_FULL)
- ->appendForm($form)
- ->addCancelButton($cancel_uri)
- ->addSubmitButton($submit_label);
- }
-
- $submit = id(new AphrontFormSubmitControl())
- ->addCancelButton($cancel_uri)
- ->setValue($submit_label);
-
- $form->appendChild($submit);
-
- $form_box = id(new PHUIObjectBoxView())
- ->setHeaderText($page_title)
- ->setForm($form);
-
- $crumbs = $this->buildApplicationCrumbs();
-
- if (!$is_create) {
- $crumbs->addTextCrumb($url->getMonogram(), $url->getURI());
- } else {
- $crumbs->addTextCrumb(pht('Create URL'));
- }
-
- $crumbs->addTextCrumb($page_title);
- $crumbs->setBorder(true);
-
- $object_box = id(new PHUIObjectBoxView())
- ->setHeaderText(pht('URL'))
- ->setValidationException($validation_exception)
- ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
- ->appendChild($form);
-
- $header = id(new PHUIHeaderView())
- ->setHeader($page_title)
- ->setHeaderIcon($header_icon);
-
- $view = id(new PHUITwoColumnView())
- ->setHeader($header)
- ->setFooter(array(
- $object_box,
- ));
-
- return $this->newPage()
- ->setTitle($page_title)
- ->setCrumbs($crumbs)
- ->appendChild($view);
+ return id(new PhabricatorPhurlURLEditEngine())
+ ->setController($this)
+ ->buildResponse();
}
}
diff --git a/src/applications/phurl/editor/PhabricatorPhurlURLEditEngine.php b/src/applications/phurl/editor/PhabricatorPhurlURLEditEngine.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phurl/editor/PhabricatorPhurlURLEditEngine.php
@@ -0,0 +1,104 @@
+<?php
+
+final class PhabricatorPhurlURLEditEngine
+ extends PhabricatorEditEngine {
+
+ const ENGINECONST = 'phurl.url';
+
+ public function getEngineName() {
+ return pht('Phurl');
+ }
+
+ public function getEngineApplicationClass() {
+ return 'PhabricatorPhurlApplication';
+ }
+
+ public function getSummaryHeader() {
+ return pht('Configure Phurl Forms');
+ }
+
+ public function getSummaryText() {
+ return pht('Configure creation and editing forms in Phurl.');
+ }
+
+ protected function newEditableObject() {
+ return PhabricatorPhurlURL::initializeNewPhurlURL($this->getViewer());
+ }
+
+ protected function newObjectQuery() {
+ return new PhabricatorPhurlURLQuery();
+ }
+
+ protected function getObjectCreateTitleText($object) {
+ return pht('Create New URL');
+ }
+
+ protected function getObjectEditTitleText($object) {
+ return pht('Edit URL: %s', $object->getName());
+ }
+
+ protected function getObjectEditShortText($object) {
+ return $object->getName();
+ }
+
+ protected function getObjectCreateShortText() {
+ return pht('Create URL');
+ }
+
+ protected function getObjectName() {
+ return pht('URL');
+ }
+
+ protected function getObjectCreateCancelURI($object) {
+ return $this->getApplication()->getApplicationURI('/');
+ }
+
+ protected function getEditorURI() {
+ return $this->getApplication()->getApplicationURI('url/edit/');
+ }
+
+ protected function getObjectViewURI($object) {
+ return $object->getURI();
+ }
+
+ protected function getCreateNewObjectPolicy() {
+ return $this->getApplication()->getPolicy(
+ PhabricatorPhurlURLCreateCapability::CAPABILITY);
+ }
+
+ protected function buildCustomEditFields($object) {
+
+ return array(
+ id(new PhabricatorTextEditField())
+ ->setKey('name')
+ ->setLabel(pht('Name'))
+ ->setDescription(pht('URL name.'))
+ ->setConduitTypeDescription(pht('New URL name.'))
+ ->setTransactionType(PhabricatorPhurlURLTransaction::TYPE_NAME)
+ ->setValue($object->getName()),
+ id(new PhabricatorTextEditField())
+ ->setKey('url')
+ ->setLabel(pht('URL'))
+ ->setDescription(pht('The URL to shorten.'))
+ ->setConduitTypeDescription(pht('New URL.'))
+ ->setValue($object->getLongURL())
+ ->setIsRequired(true)
+ ->setTransactionType(PhabricatorPhurlURLTransaction::TYPE_URL),
+ id(new PhabricatorTextEditField())
+ ->setKey('alias')
+ ->setLabel(pht('Alias'))
+ ->setTransactionType(PhabricatorPhurlURLTransaction::TYPE_ALIAS)
+ ->setDescription(pht('The alias to give the URL.'))
+ ->setConduitTypeDescription(pht('New alias.'))
+ ->setValue($object->getAlias()),
+ id(new PhabricatorRemarkupEditField())
+ ->setKey('description')
+ ->setLabel(pht('Description'))
+ ->setDescription(pht('URL long description.'))
+ ->setConduitTypeDescription(pht('New URL description.'))
+ ->setTransactionType(PhabricatorPhurlURLTransaction::TYPE_DESCRIPTION)
+ ->setValue($object->getDescription()),
+ );
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 21, 6:09 PM (14 h, 27 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6915145
Default Alt Text
D16573.id.diff (16 KB)

Event Timeline