1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-23 15:22:41 +01:00

Update PhamePost to EditEngine

Summary: Allows create and edit workflows through EditEngine. Not sure I did the 'blog' stuff correct.

Test Plan: Create a new post, edit a post, move a post.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D14802
This commit is contained in:
Chad Little 2015-12-27 17:38:25 -08:00
parent 6fe882e50a
commit 10ed330523
4 changed files with 141 additions and 169 deletions

View file

@ -3430,6 +3430,7 @@ phutil_register_library_map(array(
'PhamePostCommentController' => 'applications/phame/controller/post/PhamePostCommentController.php', 'PhamePostCommentController' => 'applications/phame/controller/post/PhamePostCommentController.php',
'PhamePostController' => 'applications/phame/controller/post/PhamePostController.php', 'PhamePostController' => 'applications/phame/controller/post/PhamePostController.php',
'PhamePostEditController' => 'applications/phame/controller/post/PhamePostEditController.php', 'PhamePostEditController' => 'applications/phame/controller/post/PhamePostEditController.php',
'PhamePostEditEngine' => 'applications/phame/editor/PhamePostEditEngine.php',
'PhamePostEditor' => 'applications/phame/editor/PhamePostEditor.php', 'PhamePostEditor' => 'applications/phame/editor/PhamePostEditor.php',
'PhamePostHistoryController' => 'applications/phame/controller/post/PhamePostHistoryController.php', 'PhamePostHistoryController' => 'applications/phame/controller/post/PhamePostHistoryController.php',
'PhamePostListController' => 'applications/phame/controller/post/PhamePostListController.php', 'PhamePostListController' => 'applications/phame/controller/post/PhamePostListController.php',
@ -7890,6 +7891,7 @@ phutil_register_library_map(array(
'PhamePostCommentController' => 'PhamePostController', 'PhamePostCommentController' => 'PhamePostController',
'PhamePostController' => 'PhameController', 'PhamePostController' => 'PhameController',
'PhamePostEditController' => 'PhamePostController', 'PhamePostEditController' => 'PhamePostController',
'PhamePostEditEngine' => 'PhabricatorEditEngine',
'PhamePostEditor' => 'PhabricatorApplicationTransactionEditor', 'PhamePostEditor' => 'PhabricatorApplicationTransactionEditor',
'PhamePostHistoryController' => 'PhamePostController', 'PhamePostHistoryController' => 'PhamePostController',
'PhamePostListController' => 'PhamePostController', 'PhamePostListController' => 'PhamePostController',

View file

@ -28,10 +28,18 @@ final class PhameHomeController extends PhamePostController {
->withVisibility(PhameConstants::VISIBILITY_PUBLISHED) ->withVisibility(PhameConstants::VISIBILITY_PUBLISHED)
->executeWithCursorPager($pager); ->executeWithCursorPager($pager);
if ($posts) {
$post_list = id(new PhamePostListView()) $post_list = id(new PhamePostListView())
->setPosts($posts) ->setPosts($posts)
->setViewer($viewer) ->setViewer($viewer)
->showBlog(true); ->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 { } else {
$create_button = id(new PHUIButtonView()) $create_button = id(new PHUIButtonView())
->setTag('a') ->setTag('a')
@ -43,7 +51,7 @@ final class PhameHomeController extends PhamePostController {
->setIcon('fa-star') ->setIcon('fa-star')
->setTitle('Welcome to Phame') ->setTitle('Welcome to Phame')
->setDescription( ->setDescription(
pht('There aren\'t any visible Blog Posts.')) pht('There aren\'t any visible blog posts.'))
->addAction($create_button); ->addAction($create_button);
} }

View file

@ -6,10 +6,6 @@ final class PhamePostEditController extends PhamePostController {
$viewer = $request->getViewer(); $viewer = $request->getViewer();
$id = $request->getURIData('id'); $id = $request->getURIData('id');
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(
pht('Blogs'),
$this->getApplicationURI('blog/'));
if ($id) { if ($id) {
$post = id(new PhamePostQuery()) $post = id(new PhamePostQuery())
->setViewer($viewer) ->setViewer($viewer)
@ -22,173 +18,29 @@ final class PhamePostEditController extends PhamePostController {
if (!$post) { if (!$post) {
return new Aphront404Response(); return new Aphront404Response();
} }
$blog_id = $post->getBlog()->getID();
$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();
} else { } else {
$blog_id = $request->getInt('blog');
}
$blog = id(new PhameBlogQuery()) $blog = id(new PhameBlogQuery())
->setViewer($viewer) ->setViewer($viewer)
->withIDs(array($request->getInt('blog'))) ->withIDs(array($blog_id))
->requireCapabilities( ->requireCapabilities(
array( array(
PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT, PhabricatorPolicyCapability::CAN_EDIT,
)) ))
->executeOne(); ->executeOne();
if (!$blog) { if (!$blog) {
return new Aphront404Response(); return new Aphront404Response();
} }
$v_projects = array();
$v_cc = array();
$post = PhamePost::initializePost($viewer, $blog); return id(new PhamePostEditEngine())
$cancel_uri = $this->getApplicationURI('/blog/view/'.$blog->getID().'/'); ->setController($this)
->setBlog($blog)
$submit_button = pht('Create Post'); ->buildResponse();
$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);
}
}
$handle = id(new PhabricatorHandleQuery())
->setViewer($viewer)
->withPHIDs(array($post->getBlogPHID()))
->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);
return $this->newPage()
->setTitle($page_title)
->setCrumbs($crumbs)
->appendChild(
array(
$form_box,
$preview,
));
} }
} }

View file

@ -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)),
);
}
}