Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15331813
D14398.id34803.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
15 KB
Referenced Files
None
Subscribers
None
D14398.id34803.diff
View Options
diff --git a/src/applications/transactions/editengine/PhabricatorApplicationEditEngine.php b/src/applications/transactions/editengine/PhabricatorApplicationEditEngine.php
--- a/src/applications/transactions/editengine/PhabricatorApplicationEditEngine.php
+++ b/src/applications/transactions/editengine/PhabricatorApplicationEditEngine.php
@@ -2,7 +2,13 @@
/**
+ * @task fields Managing Fields
+ * @task text Display Text
+ * @task uri Managing URIs
+ * @task load Creating and Loading Objects
* @task web Responding to Web Requests
+ * @task edit Responding to Edit Requests
+ * @task http Responding to HTTP Parameter Requests
* @task conduit Responding to Conduit Requests
*/
abstract class PhabricatorApplicationEditEngine extends Phobject {
@@ -30,6 +36,12 @@
return $this->controller;
}
+
+/* -( Managing Fields )---------------------------------------------------- */
+
+
+ abstract protected function buildCustomEditFields($object);
+
final protected function buildEditFields($object) {
$viewer = $this->getViewer();
$editor = $object->getApplicationTransactionEditor();
@@ -176,39 +188,95 @@
}
}
+ foreach ($fields as $field) {
+ $field
+ ->setViewer($viewer)
+ ->setObject($object);
+ }
+
return $fields;
}
- abstract protected function newEditableObject();
- abstract protected function newObjectQuery();
- abstract protected function buildCustomEditFields($object);
+/* -( Display Text )------------------------------------------------------- */
+
+
+ /**
+ * @task text
+ */
abstract protected function getObjectCreateTitleText($object);
+
+
+ /**
+ * @task text
+ */
abstract protected function getObjectEditTitleText($object);
+
+
+ /**
+ * @task text
+ */
abstract protected function getObjectCreateShortText($object);
+
+
+ /**
+ * @task text
+ */
abstract protected function getObjectEditShortText($object);
+
+
+ /**
+ * @task text
+ */
+ protected function getObjectCreateButtonText($object) {
+ return $this->getObjectCreateTitleText($object);
+ }
+
+
+ /**
+ * @task text
+ */
+ protected function getObjectEditButtonText($object) {
+ return pht('Save Changes');
+ }
+
+
+/* -( Managing URIs )------------------------------------------------------ */
+
+
+ /**
+ * @task uri
+ */
abstract protected function getObjectViewURI($object);
+
+ /**
+ * @task uri
+ */
protected function getObjectEditURI($object) {
return $this->getController()->getApplicationURI('edit/');
}
+
+ /**
+ * @task uri
+ */
protected function getObjectCreateCancelURI($object) {
return $this->getController()->getApplicationURI();
}
+
+ /**
+ * @task uri
+ */
protected function getObjectEditCancelURI($object) {
return $this->getObjectViewURI($object);
}
- protected function getObjectCreateButtonText($object) {
- return $this->getObjectCreateTitleText($object);
- }
-
- protected function getObjectEditButtonText($object) {
- return pht('Save Changes');
- }
+ /**
+ * @task uri
+ */
protected function getEditURI($object, $path = null) {
$parts = array(
$this->getObjectEditURI($object),
@@ -225,53 +293,173 @@
return implode('', $parts);
}
- final protected function setIsCreate($is_create) {
+
+/* -( Creating and Loading Objects )--------------------------------------- */
+
+
+ /**
+ * Initialize a new object for creation.
+ *
+ * @return object Newly initialized object.
+ * @task load
+ */
+ abstract protected function newEditableObject();
+
+
+ /**
+ * Build an empty query for objects.
+ *
+ * @return PhabricatorPolicyAwareQuery Query.
+ * @task load
+ */
+ abstract protected function newObjectQuery();
+
+
+ /**
+ * Test if this workflow is creating a new object or editing an existing one.
+ *
+ * @return bool True if a new object is being created.
+ * @task load
+ */
+ final protected function getIsCreate() {
+ return $this->isCreate;
+ }
+
+
+ /**
+ * Flag this workflow as a create or edit.
+ *
+ * @param bool True if this is a create workflow.
+ * @return this
+ * @task load
+ */
+ private function setIsCreate($is_create) {
$this->isCreate = $is_create;
return $this;
}
- final protected function getIsCreate() {
- return $this->isCreate;
+
+ /**
+ * Load an object by ID.
+ *
+ * @param int Object ID.
+ * @return object|null Object, or null if no such object exists.
+ * @task load
+ */
+ private function newObjectFromID($id) {
+ $query = $this->newObjectQuery()
+ ->withIDs(array($id));
+
+ return $this->newObjectFromQuery($query);
+ }
+
+
+ /**
+ * Load an object by PHID.
+ *
+ * @param phid Object PHID.
+ * @return object|null Object, or null if no such object exists.
+ * @task load
+ */
+ private function newObjectFromPHID($phid) {
+ $query = $this->newObjectQuery()
+ ->withPHIDs(array($phid));
+
+ return $this->newObjectFromQuery($query);
+ }
+
+
+ /**
+ * Load an object given a configured query.
+ *
+ * @param PhabricatorPolicyAwareQuery Configured query.
+ * @return object|null Object, or null if no such object exists.
+ * @task load
+ */
+ private function newObjectFromQuery(PhabricatorPolicyAwareQuery $query) {
+ $viewer = $this->getViewer();
+
+ $object = $query
+ ->setViewer($viewer)
+ ->requireCapabilities(
+ array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ PhabricatorPolicyCapability::CAN_EDIT,
+ ))
+ ->executeOne();
+ if (!$object) {
+ return null;
+ }
+
+ return $object;
}
+
+/* -( Responding to Web Requests )----------------------------------------- */
+
+
final public function buildResponse() {
- $controller = $this->getController();
$viewer = $this->getViewer();
+ $controller = $this->getController();
$request = $controller->getRequest();
$id = $request->getURIData('id');
if ($id) {
- $object = $this->newObjectQuery()
- ->setViewer($viewer)
- ->withIDs(array($id))
- ->requireCapabilities(
- array(
- PhabricatorPolicyCapability::CAN_VIEW,
- PhabricatorPolicyCapability::CAN_EDIT,
- ))
- ->executeOne();
+ $this->setIsCreate(false);
+ $object = $this->newObjectFromID($id);
if (!$object) {
return new Aphront404Response();
}
- $this->setIsCreate(false);
} else {
- $object = $this->newEditableObject();
$this->setIsCreate(true);
- }
-
- $fields = $this->buildEditFields($object);
-
- foreach ($fields as $field) {
- $field
- ->setViewer($viewer)
- ->setObject($object);
+ $object = $this->newEditableObject();
}
$action = $request->getURIData('editAction');
switch ($action) {
case 'parameters':
- return $this->buildParametersResponse($object, $fields);
+ return $this->buildParametersResponse($object);
+ default:
+ return $this->buildEditResponse($object);
}
+ }
+
+ private function buildCrumbs($object, $final = false) {
+ $controller = $this->getcontroller();
+
+ $crumbs = $controller->buildApplicationCrumbsForEditEngine();
+ if ($this->getIsCreate()) {
+ $create_text = $this->getObjectCreateShortText($object);
+ if ($final) {
+ $crumbs->addTextCrumb($create_text);
+ } else {
+ $edit_uri = $this->getEditURI($object);
+ $crumbs->addTextCrumb($create_text, $edit_uri);
+ }
+ } else {
+ $crumbs->addTextCrumb(
+ $this->getObjectEditShortText($object),
+ $this->getObjectViewURI($object));
+
+ $edit_text = pht('Edit');
+ if ($final) {
+ $crumbs->addTextCrumb($edit_text);
+ } else {
+ $edit_uri = $this->getEditURI($object);
+ $crumbs->addTextCrumb($edit_text, $edit_uri);
+ }
+ }
+
+ return $crumbs;
+ }
+
+ private function buildEditResponse($object) {
+ $viewer = $this->getViewer();
+ $controller = $this->getController();
+ $request = $controller->getRequest();
+
+ $fields = $this->buildEditFields($object);
+ $template = $object->getApplicationTransactionTemplate();
$validation_exception = null;
if ($request->isFormPost()) {
@@ -279,8 +467,6 @@
$field->readValueFromSubmit($request);
}
- $template = $object->getApplicationTransactionTemplate();
-
$xactions = array();
foreach ($fields as $field) {
$xactions[] = $field->generateTransaction(clone $template);
@@ -289,8 +475,7 @@
$editor = $object->getApplicationTransactionEditor()
->setActor($viewer)
->setContentSourceFromRequest($request)
- ->setContinueOnNoEffect(true)
- ->setContinueOnMissingFields(false);
+ ->setContinueOnNoEffect(true);
try {
@@ -313,49 +498,26 @@
}
}
- $box = id(new PHUIObjectBoxView())
- ->setUser($viewer);
-
- $crumbs = $this->buildCrumbs($object, $final = true);
+ $action_button = $this->buildEditFormActionButton($object);
if ($this->getIsCreate()) {
$header_text = $this->getObjectCreateTitleText($object);
-
- $cancel_uri = $this->getObjectCreateCancelURI($object);
- $submit_button = $this->getObjectCreateButtonText($object);
} else {
$header_text = $this->getObjectEditTitleText($object);
-
- $cancel_uri = $this->getObjectEditCancelURI($object);
- $submit_button = $this->getObjectEditButtonText($object);
}
$header = id(new PHUIHeaderView())
- ->setHeader($header_text);
-
- $action_button = $this->buildEditFormActionButton($object);
-
- $header->addActionLink($action_button);
-
- $box->setHeader($header);
-
- $form = id(new AphrontFormView())
- ->setUser($viewer);
-
- foreach ($fields as $field) {
- $field->appendToForm($form);
- }
+ ->setHeader($header_text)
+ ->addActionLink($action_button);
- $form->appendControl(
- id(new AphrontFormSubmitControl())
- ->addCancelButton($cancel_uri)
- ->setValue($submit_button));
-
- $box->appendChild($form);
+ $crumbs = $this->buildCrumbs($object, $final = true);
+ $form = $this->buildEditForm($object, $fields);
- if ($validation_exception) {
- $box->setValidationException($validation_exception);
- }
+ $box = id(new PHUIObjectBoxView())
+ ->setUser($viewer)
+ ->setHeader($header)
+ ->setValidationException($validation_exception)
+ ->appendChild($form);
return $controller->newPage()
->setTitle($header_text)
@@ -363,64 +525,30 @@
->appendChild($box);
}
- private function buildParametersResponse($object, array $fields) {
- $controller = $this->getController();
+ private function buildEditForm($object, array $fields) {
$viewer = $this->getViewer();
- $request = $controller->getRequest();
-
- $crumbs = $this->buildCrumbs($object);
- $crumbs->addTextCrumb(pht('HTTP Parameters'));
- $crumbs->setBorder(true);
-
- $header = id(new PHUIHeaderView())
- ->setHeader(
- pht(
- 'HTTP Parameters: %s',
- $this->getObjectCreateShortText($object)));
- $document = id(new PHUIDocumentViewPro())
- ->setUser($viewer)
- ->setHeader($header);
-
- $document->appendChild(
- id(new PhabricatorApplicationEditHTTPParameterHelpView())
- ->setUser($viewer)
- ->setFields($fields));
-
- return $controller->newPage()
- ->setTitle(pht('HTTP Parameters'))
- ->setCrumbs($crumbs)
- ->addClass('pro-white-background')
- ->appendChild($document);
- }
+ $form = id(new AphrontFormView())
+ ->setUser($viewer);
- private function buildCrumbs($object, $final = false) {
- $controller = $this->getcontroller();
+ foreach ($fields as $field) {
+ $field->appendToForm($form);
+ }
- $crumbs = $controller->buildApplicationCrumbsForEditEngine();
if ($this->getIsCreate()) {
- $create_text = $this->getObjectCreateShortText($object);
- if ($final) {
- $crumbs->addTextCrumb($create_text);
- } else {
- $edit_uri = $this->getEditURI($object);
- $crumbs->addTextCrumb($create_text, $edit_uri);
- }
+ $cancel_uri = $this->getObjectCreateCancelURI($object);
+ $submit_button = $this->getObjectCreateButtonText($object);
} else {
- $crumbs->addTextCrumb(
- $this->getObjectEditShortText($object),
- $this->getObjectViewURI($object));
-
- $edit_text = pht('Edit');
- if ($final) {
- $crumbs->addTextCrumb($edit_text);
- } else {
- $edit_uri = $this->getEditURI($object);
- $crumbs->addTextCrumb($edit_text, $edit_uri);
- }
+ $cancel_uri = $this->getObjectEditCancelURI($object);
+ $submit_button = $this->getObjectEditButtonText($object);
}
- return $crumbs;
+ $form->appendControl(
+ id(new AphrontFormSubmitControl())
+ ->addCancelButton($cancel_uri)
+ ->setValue($submit_button));
+
+ return $form;
}
private function buildEditFormActionButton($object) {
@@ -455,6 +583,50 @@
}
+/* -( Responding to HTTP Parameter Requests )------------------------------ */
+
+
+ /**
+ * Respond to a request for documentation on HTTP parameters.
+ *
+ * @param object Editable object.
+ * @return AphrontResponse Response object.
+ * @task http
+ */
+ private function buildParametersResponse($object) {
+ $controller = $this->getController();
+ $viewer = $this->getViewer();
+ $request = $controller->getRequest();
+ $fields = $this->buildEditFields($object);
+
+ $crumbs = $this->buildCrumbs($object);
+ $crumbs->addTextCrumb(pht('HTTP Parameters'));
+ $crumbs->setBorder(true);
+
+ $header_text = pht(
+ 'HTTP Parameters: %s',
+ $this->getObjectCreateShortText($object));
+
+ $header = id(new PHUIHeaderView())
+ ->setHeader($header_text);
+
+ $help_view = id(new PhabricatorApplicationEditHTTPParameterHelpView())
+ ->setUser($viewer)
+ ->setFields($fields);
+
+ $document = id(new PHUIDocumentViewPro())
+ ->setUser($viewer)
+ ->setHeader($header)
+ ->appendChild($help_view);
+
+ return $controller->newPage()
+ ->setTitle(pht('HTTP Parameters'))
+ ->setCrumbs($crumbs)
+ ->addClass('pro-white-background')
+ ->appendChild($document);
+ }
+
+
/* -( Conduit )------------------------------------------------------------ */
@@ -471,32 +643,18 @@
$phid = $request->getValue('objectPHID');
if ($phid) {
- $object = $this->newObjectQuery()
- ->setViewer($viewer)
- ->withPHIDs(array($phid))
- ->requireCapabilities(
- array(
- PhabricatorPolicyCapability::CAN_VIEW,
- PhabricatorPolicyCapability::CAN_EDIT,
- ))
- ->executeOne();
+ $this->setIsCreate(false);
+ $object = $this->newObjectFromPHID($phid);
if (!$object) {
throw new Exception(pht('No such object with PHID "%s".', $phid));
}
- $this->setIsCreate(false);
} else {
- $object = $this->newEditableObject();
$this->setIsCreate(true);
+ $object = $this->newEditableObject();
}
$fields = $this->buildEditFields($object);
- foreach ($fields as $field) {
- $field
- ->setViewer($viewer)
- ->setObject($object);
- }
-
$types = $this->getAllEditTypesFromFields($fields);
$template = $object->getApplicationTransactionTemplate();
@@ -619,6 +777,4 @@
}
-
-
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mar 8 2025, 1:58 PM (8 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7223429
Default Alt Text
D14398.id34803.diff (15 KB)
Attached To
Mode
D14398: Slightly improve organization of PhabricatorApplicationEditEngine
Attached
Detach File
Event Timeline
Log In to Comment