phorge/src/applications/phame/controller/blog/PhameBlogEditController.php36e2d02d6ec5master
phorge/src/applications/phame/controller/blog/PhameBlogEditController.php
36e2d02d6ec5master
PhameBlogEditController.php
PhameBlogEditController.php
ae13d3385913 | <?php | ||
---|---|---|---|
final class PhameBlogEditController | |||
extends PhameController { | |||
f16dda288d0c | public function handleRequest(AphrontRequest $request) { | ||
dbcf2e44e890 | $user = $request->getUser(); | ||
f16dda288d0c | $id = $request->getURIData('id'); | ||
if ($id) { | |||
dbcf2e44e890 | $blog = id(new PhameBlogQuery()) | ||
->setViewer($user) | |||
f16dda288d0c | ->withIDs(array($id)) | ||
dbcf2e44e890 | ->requireCapabilities( | ||
array( | |||
3cf9a5820fc9 | PhabricatorPolicyCapability::CAN_EDIT, | ||
dbcf2e44e890 | )) | ||
->executeOne(); | |||
if (!$blog) { | |||
ae13d3385913 | return new Aphront404Response(); | ||
} | |||
b072e937b5fc | $submit_button = pht('Save Changes'); | ||
$page_title = pht('Edit Blog'); | |||
$cancel_uri = $this->getApplicationURI('blog/view/'.$blog->getID().'/'); | |||
ae13d3385913 | } else { | ||
f16dda288d0c | $blog = PhameBlog::initializeNewBlog($user); | ||
b072e937b5fc | |||
$submit_button = pht('Create Blog'); | |||
$page_title = pht('Create Blog'); | |||
$cancel_uri = $this->getApplicationURI(); | |||
ae13d3385913 | } | ||
f16dda288d0c | $name = $blog->getName(); | ||
$description = $blog->getDescription(); | |||
$custom_domain = $blog->getDomain(); | |||
$skin = $blog->getSkin(); | |||
$can_view = $blog->getViewPolicy(); | |||
$can_edit = $blog->getEditPolicy(); | |||
$can_join = $blog->getJoinPolicy(); | |||
$e_name = true; | |||
$e_custom_domain = null; | |||
$e_view_policy = null; | |||
$validation_exception = null; | |||
ae13d3385913 | if ($request->isFormPost()) { | ||
9e1b64389613 | $name = $request->getStr('name'); | ||
$description = $request->getStr('description'); | |||
f16dda288d0c | $custom_domain = nonempty($request->getStr('custom_domain'), null); | ||
8355f3592f98 | $skin = $request->getStr('skin'); | ||
f16dda288d0c | $can_view = $request->getStr('can_view'); | ||
$can_edit = $request->getStr('can_edit'); | |||
$can_join = $request->getStr('can_join'); | |||
$xactions = array( | |||
id(new PhameBlogTransaction()) | |||
->setTransactionType(PhameBlogTransaction::TYPE_NAME) | |||
->setNewValue($name), | |||
id(new PhameBlogTransaction()) | |||
->setTransactionType(PhameBlogTransaction::TYPE_DESCRIPTION) | |||
->setNewValue($description), | |||
id(new PhameBlogTransaction()) | |||
->setTransactionType(PhameBlogTransaction::TYPE_DOMAIN) | |||
->setNewValue($custom_domain), | |||
id(new PhameBlogTransaction()) | |||
->setTransactionType(PhameBlogTransaction::TYPE_SKIN) | |||
->setNewValue($skin), | |||
id(new PhameBlogTransaction()) | |||
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) | |||
->setNewValue($can_view), | |||
id(new PhameBlogTransaction()) | |||
->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY) | |||
->setNewValue($can_edit), | |||
id(new PhameBlogTransaction()) | |||
->setTransactionType(PhabricatorTransactions::TYPE_JOIN_POLICY) | |||
->setNewValue($can_join), | |||
); | |||
$editor = id(new PhameBlogEditor()) | |||
->setActor($user) | |||
->setContentSourceFromRequest($request) | |||
->setContinueOnNoEffect(true); | |||
try { | |||
$editor->applyTransactions($blog, $xactions); | |||
return id(new AphrontRedirectResponse()) | |||
->setURI($this->getApplicationURI('blog/view/'.$blog->getID().'/')); | |||
} catch (PhabricatorApplicationTransactionValidationException $ex) { | |||
$validation_exception = $ex; | |||
$e_name = $validation_exception->getShortMessage( | |||
PhameBlogTransaction::TYPE_NAME); | |||
$e_custom_domain = $validation_exception->getShortMessage( | |||
PhameBlogTransaction::TYPE_DOMAIN); | |||
$e_view_policy = $validation_exception->getShortMessage( | |||
PhabricatorTransactions::TYPE_VIEW_POLICY); | |||
ae13d3385913 | } | ||
} | |||
dbcf2e44e890 | $policies = id(new PhabricatorPolicyQuery()) | ||
->setViewer($user) | |||
->setObject($blog) | |||
->execute(); | |||
b3ad8507af33 | $skins = PhameSkinSpecification::loadAllSkinSpecifications(); | ||
$skins = mpull($skins, 'getName'); | |||
ae13d3385913 | $form = id(new AphrontFormView()) | ||
->setUser($user) | |||
->appendChild( | |||
id(new AphrontFormTextControl()) | |||
8ea5c8c74ea2 | ->setLabel(pht('Name')) | ||
ae13d3385913 | ->setName('name') | ||
f16dda288d0c | ->setValue($name) | ||
ae13d3385913 | ->setID('blog-name') | ||
a22bea2a74cf | ->setError($e_name)) | ||
ae13d3385913 | ->appendChild( | ||
557cc5b29c34 | id(new PhabricatorRemarkupControl()) | ||
10b86c2aa34d | ->setUser($user) | ||
->setLabel(pht('Description')) | |||
->setName('description') | |||
f16dda288d0c | ->setValue($description) | ||
10b86c2aa34d | ->setID('blog-description') | ||
->setUser($user) | |||
->setDisableMacros(true)) | |||
ae13d3385913 | ->appendChild( | ||
dbcf2e44e890 | id(new AphrontFormPolicyControl()) | ||
->setUser($user) | |||
->setCapability(PhabricatorPolicyCapability::CAN_VIEW) | |||
->setPolicyObject($blog) | |||
->setPolicies($policies) | |||
f16dda288d0c | ->setError($e_view_policy) | ||
->setValue($can_view) | |||
dbcf2e44e890 | ->setName('can_view')) | ||
->appendChild( | |||
id(new AphrontFormPolicyControl()) | |||
->setUser($user) | |||
->setCapability(PhabricatorPolicyCapability::CAN_EDIT) | |||
->setPolicyObject($blog) | |||
->setPolicies($policies) | |||
f16dda288d0c | ->setValue($can_edit) | ||
dbcf2e44e890 | ->setName('can_edit')) | ||
->appendChild( | |||
id(new AphrontFormPolicyControl()) | |||
->setUser($user) | |||
->setCapability(PhabricatorPolicyCapability::CAN_JOIN) | |||
->setPolicyObject($blog) | |||
->setPolicies($policies) | |||
f16dda288d0c | ->setValue($can_join) | ||
dbcf2e44e890 | ->setName('can_join')) | ||
9e1b64389613 | ->appendChild( | ||
id(new AphrontFormTextControl()) | |||
8ea5c8c74ea2 | ->setLabel(pht('Custom Domain')) | ||
9e1b64389613 | ->setName('custom_domain') | ||
f16dda288d0c | ->setValue($custom_domain) | ||
8ea5c8c74ea2 | ->setCaption( | ||
36e2d02d6ec5 | pht('Must include at least one dot (.), e.g. %s', 'blog.example.com')) | ||
a22bea2a74cf | ->setError($e_custom_domain)) | ||
8355f3592f98 | ->appendChild( | ||
id(new AphrontFormSelectControl()) | |||
8ea5c8c74ea2 | ->setLabel(pht('Skin')) | ||
8355f3592f98 | ->setName('skin') | ||
f16dda288d0c | ->setValue($skin) | ||
a22bea2a74cf | ->setOptions($skins)) | ||
9e1b64389613 | ->appendChild( | ||
id(new AphrontFormSubmitControl()) | |||
b072e937b5fc | ->addCancelButton($cancel_uri) | ||
a22bea2a74cf | ->setValue($submit_button)); | ||
ae13d3385913 | |||
9be7a948f93c | $form_box = id(new PHUIObjectBoxView()) | ||
fe2a96e37ff0 | ->setHeaderText($page_title) | ||
f16dda288d0c | ->setValidationException($validation_exception) | ||
fe2a96e37ff0 | ->setForm($form); | ||
8ea5c8c74ea2 | $crumbs = $this->buildApplicationCrumbs(); | ||
a5dc9067af0c | $crumbs->addTextCrumb($page_title, $this->getApplicationURI('blog/new')); | ||
8ea5c8c74ea2 | |||
9b15aa195e2f | $nav = $this->renderSideNavFilterView(); | ||
f16dda288d0c | $nav->selectFilter($id ? null : 'blog/new'); | ||
b072e937b5fc | $nav->appendChild( | ||
ae13d3385913 | array( | ||
8ea5c8c74ea2 | $crumbs, | ||
fe2a96e37ff0 | $form_box, | ||
b072e937b5fc | )); | ||
return $this->buildApplicationPage( | |||
$nav, | |||
ae13d3385913 | array( | ||
8ea5c8c74ea2 | 'title' => $page_title, | ||
ae13d3385913 | )); | ||
} | |||
} |
Owner Packages
Owner Packages
- No Owners