1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-02 01:48:23 +01:00

Use PhabricatorCustomField infrastructure to render Releeph custom fields on the edit screen

Summary:
Ref T3718. This moves custom field rendering on the edit screen to PhabricatorCustomField and makes all the APIs conformant.

We still run through edit with both old-school and new-school sets of fields, because the actual editing isn't on the new stuff yet. That will happen in a diff or two.

Test Plan: Edited a request; intentionally introduced errors and verified the form behaved as expected.

Reviewers: btrahan, testuser1122344

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3718

Differential Revision: https://secure.phabricator.com/D6756
This commit is contained in:
epriestley 2013-08-14 15:36:13 -07:00
parent d02eb46ad6
commit 7821c98053
5 changed files with 42 additions and 27 deletions

View file

@ -49,6 +49,18 @@ final class ReleephRequestEditController extends ReleephProjectController {
->setReleephRequest($rq); ->setReleephRequest($rq);
} }
$field_list = PhabricatorCustomField::getObjectFields(
$rq,
PhabricatorCustomField::ROLE_EDIT);
foreach ($field_list->getFields() as $field) {
$field
->setReleephProject($releeph_project)
->setReleephBranch($releeph_branch)
->setReleephRequest($rq);
}
$field_list->readFieldsFromStorage($rq);
// <aidehua> epriestley: Is it common to pass around a referer URL to // <aidehua> epriestley: Is it common to pass around a referer URL to
// return from whence one came? [...] // return from whence one came? [...]
// <epriestley> If you only have two places, maybe consider some parameter // <epriestley> If you only have two places, maybe consider some parameter
@ -126,6 +138,12 @@ final class ReleephRequestEditController extends ReleephProjectController {
} }
} }
// TODO: This should happen implicitly while building transactions
// instead.
foreach ($field_list->getFields() as $field) {
$field->readValueFromRequest($request);
}
if (!$errors) { if (!$errors) {
foreach ($fields as $field) { foreach ($fields as $field) {
if ($field->isEditable()) { if ($field->isEditable()) {
@ -243,13 +261,7 @@ final class ReleephRequestEditController extends ReleephProjectController {
} }
} }
// Fields $field_list->appendFieldsToForm($form);
foreach ($fields as $field) {
if ($field->isEditable()) {
$control = $field->renderReleephEditControl($request);
$form->appendChild($control);
}
}
$crumbs = $this->buildApplicationCrumbs(); $crumbs = $this->buildApplicationCrumbs();

View file

@ -4,6 +4,15 @@ abstract class ReleephFieldSpecification
extends PhabricatorCustomField extends PhabricatorCustomField
implements PhabricatorMarkupInterface { implements PhabricatorMarkupInterface {
// TODO: This is temporary, until ReleephFieldSpecification is more conformant
// to PhabricatorCustomField.
private $requestValue;
public function readValueFromRequest(AphrontRequest $request) {
$this->requestValue = $request->getStr($this->getRequiredStorageKey());
return $this;
}
abstract public function getName(); abstract public function getName();
/* -( Storage )------------------------------------------------------------ */ /* -( Storage )------------------------------------------------------------ */
@ -28,6 +37,10 @@ abstract class ReleephFieldSpecification
return $key; return $key;
} }
public function shouldAppearInEditView() {
return $this->isEditable();
}
final public function isEditable() { final public function isEditable() {
return $this->getStorageKey() !== null; return $this->getStorageKey() !== null;
} }
@ -38,6 +51,10 @@ abstract class ReleephFieldSpecification
* N-squared times, each time for R ReleephRequests. * N-squared times, each time for R ReleephRequests.
*/ */
final public function getValue() { final public function getValue() {
if ($this->requestValue !== null) {
return $this->requestValue;
}
$key = $this->getRequiredStorageKey(); $key = $this->getRequiredStorageKey();
return $this->getReleephRequest()->getDetail($key); return $this->getReleephRequest()->getDetail($key);
} }
@ -82,13 +99,6 @@ abstract class ReleephFieldSpecification
} }
/* -( Edit View )---------------------------------------------------------- */
public function renderReleephEditControl(AphrontRequest $request) {
throw new ReleephFieldSpecificationIncompleteException($this);
}
/* -( Conduit )------------------------------------------------------------ */ /* -( Conduit )------------------------------------------------------------ */
public function getKeyForConduit() { public function getKeyForConduit() {

View file

@ -39,16 +39,11 @@ abstract class ReleephLevelFieldSpecification
return $this->getNameForLevel($level); return $this->getNameForLevel($level);
} }
public function renderReleephEditControl(AphrontRequest $request) { public function renderEditControl() {
$control_name = $this->getRequiredStorageKey(); $control_name = $this->getRequiredStorageKey();
$all_levels = $this->getLevels(); $all_levels = $this->getLevels();
$level = $request->getStr($control_name); $level = $this->getCanonicalLevel($this->getValue());
if (!$level) {
$level = $this->getCanonicalLevel($this->getValue());
}
if (!$level) { if (!$level) {
$level = $this->getDefaultLevel(); $level = $this->getDefaultLevel();
} }

View file

@ -35,13 +35,12 @@ final class ReleephReasonFieldSpecification
private $error = true; private $error = true;
public function renderReleephEditControl(AphrontRequest $request) { public function renderEditControl() {
$reason = $request->getStr('reason', $this->getValue());
return id(new AphrontFormTextAreaControl()) return id(new AphrontFormTextAreaControl())
->setLabel('Reason') ->setLabel('Reason')
->setName('reason') ->setName('reason')
->setError($this->error) ->setError($this->error)
->setValue($reason); ->setValue($this->getValue());
} }
public function validate($reason) { public function validate($reason) {

View file

@ -19,13 +19,12 @@ final class ReleephSummaryFieldSpecification
private $error = false; private $error = false;
public function renderReleephEditControl(AphrontRequest $request) { public function renderEditControl() {
$summary = $request->getStr('summary', $this->getValue());
return id(new AphrontFormTextControl()) return id(new AphrontFormTextControl())
->setLabel('Summary') ->setLabel('Summary')
->setName('summary') ->setName('summary')
->setError($this->error) ->setError($this->error)
->setValue($summary) ->setValue($this->getValue())
->setCaption( ->setCaption(
'Leave this blank to use the original commit title'); 'Leave this blank to use the original commit title');
} }