Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14041225
D14802.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
12 KB
Referenced Files
None
Subscribers
None
D14802.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
@@ -3430,6 +3430,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',
@@ -7890,6 +7891,7 @@
'PhamePostCommentController' => 'PhamePostController',
'PhamePostController' => 'PhameController',
'PhamePostEditController' => 'PhamePostController',
+ 'PhamePostEditEngine' => 'PhabricatorEditEngine',
'PhamePostEditor' => 'PhabricatorApplicationTransactionEditor',
'PhamePostHistoryController' => 'PhamePostController',
'PhamePostListController' => 'PhamePostController',
diff --git a/src/applications/phame/controller/PhameHomeController.php b/src/applications/phame/controller/PhameHomeController.php
--- a/src/applications/phame/controller/PhameHomeController.php
+++ b/src/applications/phame/controller/PhameHomeController.php
@@ -28,10 +28,18 @@
->withVisibility(PhameConstants::VISIBILITY_PUBLISHED)
->executeWithCursorPager($pager);
- $post_list = id(new PhamePostListView())
- ->setPosts($posts)
- ->setViewer($viewer)
- ->showBlog(true);
+ if ($posts) {
+ $post_list = id(new PhamePostListView())
+ ->setPosts($posts)
+ ->setViewer($viewer)
+ ->showBlog(true);
+ } else {
+ $post_list = id(new PHUIBigInfoView())
+ ->setIcon('fa-star')
+ ->setTitle('No Visible Posts')
+ ->setDescription(
+ pht('There aren\'t any visible blog posts.'));
+ }
} else {
$create_button = id(new PHUIButtonView())
->setTag('a')
@@ -43,7 +51,7 @@
->setIcon('fa-star')
->setTitle('Welcome to Phame')
->setDescription(
- pht('There aren\'t any visible Blog Posts.'))
+ pht('There aren\'t any visible blog posts.'))
->addAction($create_button);
}
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,110 @@
+<?php
+
+final class PhamePostEditEngine
+ extends PhabricatorEditEngine {
+
+ private $blog;
+
+ const ENGINECONST = 'phame.post';
+
+ public function getEngineName() {
+ return pht('Blog Posts');
+ }
+
+ public function getSummaryHeader() {
+ return pht('Configure Blog Post Forms');
+ }
+
+ public function getSummaryText() {
+ return pht('Configure creation and editing blog posts in Phame.');
+ }
+
+ public function setBlog(PhameBlog $blog) {
+ $this->blog = $blog;
+ return $this;
+ }
+
+ public function getEngineApplicationClass() {
+ return 'PhabricatorPhameApplication';
+ }
+
+ protected function newEditableObject() {
+ $viewer = $this->getViewer();
+
+ if ($this->blog) {
+ $blog = $this->blog;
+ } else {
+ $blog = PhameBlog::initializeNewBlog($viewer);
+ }
+
+ return PhamePost::initializePost($viewer, $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) {
+
+ if ($this->blog) {
+ $blog_title = pht('Blog: %s', $this->blog->getName());
+ } else {
+ $blog_title = pht('Sample Blog Title');
+ }
+
+ return array(
+ id(new PhabricatorInstructionsEditField())
+ ->setValue($blog_title),
+ 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())
+ ->setPreviewPanel(
+ id(new PHUIRemarkupPreviewPanel())
+ ->setHeader(pht('Blog Post'))
+ ->setPreviewType(PHUIRemarkupPreviewPanel::DOCUMENT)),
+ );
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 12, 4:51 PM (6 d, 15 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6740138
Default Alt Text
D14802.diff (12 KB)
Attached To
Mode
D14802: Update PhamePost to EditEngine
Attached
Detach File
Event Timeline
Log In to Comment