Page MenuHomePhabricator

D14802.id35791.diff
No OneTemporary

D14802.id35791.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
@@ -3379,6 +3379,7 @@
'PhamePostCommentController' => 'applications/phame/controller/post/PhamePostCommentController.php',
'PhamePostController' => 'applications/phame/controller/post/PhamePostController.php',
'PhamePostEditController' => 'applications/phame/controller/post/PhamePostEditController.php',
+ 'PhamePostEditEngine' => 'applications/phame/editor/PhamePostEditEngine.php',
'PhamePostEditor' => 'applications/phame/editor/PhamePostEditor.php',
'PhamePostHistoryController' => 'applications/phame/controller/post/PhamePostHistoryController.php',
'PhamePostListController' => 'applications/phame/controller/post/PhamePostListController.php',
@@ -7773,6 +7774,7 @@
'PhamePostCommentController' => 'PhamePostController',
'PhamePostController' => 'PhameController',
'PhamePostEditController' => 'PhamePostController',
+ 'PhamePostEditEngine' => 'PhabricatorEditEngine',
'PhamePostEditor' => 'PhabricatorApplicationTransactionEditor',
'PhamePostHistoryController' => 'PhamePostController',
'PhamePostListController' => 'PhamePostController',
diff --git a/src/applications/phame/controller/post/PhamePostEditController.php b/src/applications/phame/controller/post/PhamePostEditController.php
--- a/src/applications/phame/controller/post/PhamePostEditController.php
+++ b/src/applications/phame/controller/post/PhamePostEditController.php
@@ -6,10 +6,6 @@
$viewer = $request->getViewer();
$id = $request->getURIData('id');
- $crumbs = $this->buildApplicationCrumbs();
- $crumbs->addTextCrumb(
- pht('Blogs'),
- $this->getApplicationURI('blog/'));
if ($id) {
$post = id(new PhamePostQuery())
->setViewer($viewer)
@@ -22,173 +18,29 @@
if (!$post) {
return new Aphront404Response();
}
-
- $cancel_uri = $this->getApplicationURI('/post/view/'.$id.'/');
- $submit_button = pht('Save Changes');
- $page_title = pht('Edit Post');
-
- $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs(
- $post->getPHID(),
- PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
- $v_projects = array_reverse($v_projects);
- $v_cc = PhabricatorSubscribersQuery::loadSubscribersForPHID(
- $post->getPHID());
- $blog = $post->getBlog();
-
-
+ $blog_id = $post->getBlog()->getID();
} else {
- $blog = id(new PhameBlogQuery())
- ->setViewer($viewer)
- ->withIDs(array($request->getInt('blog')))
- ->requireCapabilities(
- array(
- PhabricatorPolicyCapability::CAN_VIEW,
- PhabricatorPolicyCapability::CAN_EDIT,
- ))
- ->executeOne();
- if (!$blog) {
- return new Aphront404Response();
- }
- $v_projects = array();
- $v_cc = array();
-
- $post = PhamePost::initializePost($viewer, $blog);
- $cancel_uri = $this->getApplicationURI('/blog/view/'.$blog->getID().'/');
-
- $submit_button = pht('Create Post');
- $page_title = pht('Create Post');
- }
-
- $title = $post->getTitle();
- $body = $post->getBody();
- $visibility = $post->getVisibility();
-
- $e_title = true;
- $validation_exception = null;
- if ($request->isFormPost()) {
- $title = $request->getStr('title');
- $body = $request->getStr('body');
- $v_projects = $request->getArr('projects');
- $v_cc = $request->getArr('cc');
- $visibility = $request->getInt('visibility');
-
- $xactions = array(
- id(new PhamePostTransaction())
- ->setTransactionType(PhamePostTransaction::TYPE_TITLE)
- ->setNewValue($title),
- id(new PhamePostTransaction())
- ->setTransactionType(PhamePostTransaction::TYPE_BODY)
- ->setNewValue($body),
- id(new PhamePostTransaction())
- ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY)
- ->setNewValue($visibility),
- id(new PhamePostTransaction())
- ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)
- ->setNewValue(array('=' => $v_cc)),
-
- );
-
- $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
- $xactions[] = id(new PhamePostTransaction())
- ->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
- ->setMetadataValue('edge:type', $proj_edge_type)
- ->setNewValue(array('=' => array_fuse($v_projects)));
-
- $editor = id(new PhamePostEditor())
- ->setActor($viewer)
- ->setContentSourceFromRequest($request)
- ->setContinueOnNoEffect(true);
-
- try {
- $editor->applyTransactions($post, $xactions);
-
- $uri = $post->getViewURI();
- return id(new AphrontRedirectResponse())->setURI($uri);
- } catch (PhabricatorApplicationTransactionValidationException $ex) {
- $validation_exception = $ex;
- $e_title = $validation_exception->getShortMessage(
- PhamePostTransaction::TYPE_TITLE);
- }
+ $blog_id = $request->getInt('blog');
}
- $handle = id(new PhabricatorHandleQuery())
+ $blog = id(new PhameBlogQuery())
->setViewer($viewer)
- ->withPHIDs(array($post->getBlogPHID()))
+ ->withIDs(array($blog_id))
+ ->requireCapabilities(
+ array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ PhabricatorPolicyCapability::CAN_EDIT,
+ ))
->executeOne();
- $form = id(new AphrontFormView())
- ->setUser($viewer)
- ->addHiddenInput('blog', $request->getInt('blog'))
- ->appendChild(
- id(new AphrontFormMarkupControl())
- ->setLabel(pht('Blog'))
- ->setValue($handle->renderLink()))
- ->appendChild(
- id(new AphrontFormTextControl())
- ->setLabel(pht('Title'))
- ->setName('title')
- ->setValue($title)
- ->setID('post-title')
- ->setError($e_title))
- ->appendChild(
- id(new AphrontFormSelectControl())
- ->setLabel(pht('Visibility'))
- ->setName('visibility')
- ->setValue($visibility)
- ->setOptions(PhameConstants::getPhamePostStatusMap()))
- ->appendChild(
- id(new PhabricatorRemarkupControl())
- ->setLabel(pht('Body'))
- ->setName('body')
- ->setValue($body)
- ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
- ->setID('post-body')
- ->setUser($viewer)
- ->setDisableMacros(true))
- ->appendControl(
- id(new AphrontFormTokenizerControl())
- ->setLabel(pht('Subscribers'))
- ->setName('cc')
- ->setValue($v_cc)
- ->setUser($viewer)
- ->setDatasource(new PhabricatorMetaMTAMailableDatasource()))
- ->appendControl(
- id(new AphrontFormTokenizerControl())
- ->setLabel(pht('Projects'))
- ->setName('projects')
- ->setValue($v_projects)
- ->setDatasource(new PhabricatorProjectDatasource()))
- ->appendChild(
- id(new AphrontFormSubmitControl())
- ->addCancelButton($cancel_uri)
- ->setValue($submit_button));
-
- $preview = id(new PHUIRemarkupPreviewPanel())
- ->setHeader($post->getTitle())
- ->setPreviewURI($this->getApplicationURI('post/preview/'))
- ->setControlID('post-body')
- ->setPreviewType(PHUIRemarkupPreviewPanel::DOCUMENT);
-
- $form_box = id(new PHUIObjectBoxView())
- ->setHeaderText($page_title)
- ->setValidationException($validation_exception)
- ->setForm($form);
-
- $crumbs->addTextCrumb(
- $blog->getName(),
- $blog->getViewURI());
- $crumbs->addTextCrumb(
- $page_title,
- $cancel_uri);
+ if (!$blog) {
+ return new Aphront404Response();
+ }
- return $this->newPage()
- ->setTitle($page_title)
- ->setCrumbs($crumbs)
- ->appendChild(
- array(
- $form_box,
- $preview,
- ));
+ return id(new PhamePostEditEngine())
+ ->setController($this)
+ ->setBlog($blog)
+ ->buildResponse();
}
}
diff --git a/src/applications/phame/editor/PhamePostEditEngine.php b/src/applications/phame/editor/PhamePostEditEngine.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phame/editor/PhamePostEditEngine.php
@@ -0,0 +1,86 @@
+<?php
+
+final class PhamePostEditEngine
+ extends PhabricatorEditEngine {
+
+ private $blog;
+
+ const ENGINECONST = 'phame.post';
+
+ public function getEngineName() {
+ return pht('Blog Posts');
+ }
+
+ public function setBlog(PhameBlog $blog) {
+ $this->blog = $blog;
+ return $this;
+ }
+
+ public function getEngineApplicationClass() {
+ return 'PhabricatorPhameApplication';
+ }
+
+ protected function newEditableObject() {
+ return PhamePost::initializePost(
+ $this->getViewer(),
+ $this->blog);
+ }
+
+ protected function newObjectQuery() {
+ return new PhamePostQuery();
+ }
+
+ protected function getObjectCreateTitleText($object) {
+ return pht('Create New Post');
+ }
+
+ protected function getObjectEditTitleText($object) {
+ return pht('Edit %s', $object->getTitle());
+ }
+
+ protected function getObjectEditShortText($object) {
+ return $object->getTitle();
+ }
+
+ protected function getObjectCreateShortText() {
+ return pht('Create Post');
+ }
+
+ protected function getObjectViewURI($object) {
+ return $object->getViewURI();
+ }
+
+ protected function buildCustomEditFields($object) {
+
+ return array(
+ id(new PhabricatorInstructionsEditField())
+ ->setValue(pht('Blog: %s', $this->blog->getName())),
+ id(new PhabricatorTextEditField())
+ ->setKey('title')
+ ->setLabel(pht('Title'))
+ ->setDescription(pht('Post title.'))
+ ->setConduitDescription(pht('Retitle the post.'))
+ ->setConduitTypeDescription(pht('New post title.'))
+ ->setTransactionType(PhamePostTransaction::TYPE_TITLE)
+ ->setValue($object->getTitle()),
+ id(new PhabricatorSelectEditField())
+ ->setKey('visibility')
+ ->setLabel(pht('Visibility'))
+ ->setDescription(pht('Post visibility.'))
+ ->setConduitDescription(pht('Change post visibility.'))
+ ->setConduitTypeDescription(pht('New post visibility constant.'))
+ ->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY)
+ ->setValue($object->getVisibility())
+ ->setOptions(PhameConstants::getPhamePostStatusMap()),
+ id(new PhabricatorRemarkupEditField())
+ ->setKey('body')
+ ->setLabel(pht('Body'))
+ ->setDescription(pht('Post body.'))
+ ->setConduitDescription(pht('Change post body.'))
+ ->setConduitTypeDescription(pht('New post body.'))
+ ->setTransactionType(PhamePostTransaction::TYPE_BODY)
+ ->setValue($object->getBody()),
+ );
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Sun, Oct 20, 2:47 PM (4 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6736714
Default Alt Text
D14802.id35791.diff (10 KB)

Event Timeline