mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-22 04:31:13 +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:
parent
d02eb46ad6
commit
7821c98053
5 changed files with 42 additions and 27 deletions
|
@ -49,6 +49,18 @@ final class ReleephRequestEditController extends ReleephProjectController {
|
|||
->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
|
||||
// return from whence one came? [...]
|
||||
// <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) {
|
||||
foreach ($fields as $field) {
|
||||
if ($field->isEditable()) {
|
||||
|
@ -243,13 +261,7 @@ final class ReleephRequestEditController extends ReleephProjectController {
|
|||
}
|
||||
}
|
||||
|
||||
// Fields
|
||||
foreach ($fields as $field) {
|
||||
if ($field->isEditable()) {
|
||||
$control = $field->renderReleephEditControl($request);
|
||||
$form->appendChild($control);
|
||||
}
|
||||
}
|
||||
$field_list->appendFieldsToForm($form);
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
|
||||
|
|
|
@ -4,6 +4,15 @@ abstract class ReleephFieldSpecification
|
|||
extends PhabricatorCustomField
|
||||
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();
|
||||
|
||||
/* -( Storage )------------------------------------------------------------ */
|
||||
|
@ -28,6 +37,10 @@ abstract class ReleephFieldSpecification
|
|||
return $key;
|
||||
}
|
||||
|
||||
public function shouldAppearInEditView() {
|
||||
return $this->isEditable();
|
||||
}
|
||||
|
||||
final public function isEditable() {
|
||||
return $this->getStorageKey() !== null;
|
||||
}
|
||||
|
@ -38,6 +51,10 @@ abstract class ReleephFieldSpecification
|
|||
* N-squared times, each time for R ReleephRequests.
|
||||
*/
|
||||
final public function getValue() {
|
||||
if ($this->requestValue !== null) {
|
||||
return $this->requestValue;
|
||||
}
|
||||
|
||||
$key = $this->getRequiredStorageKey();
|
||||
return $this->getReleephRequest()->getDetail($key);
|
||||
}
|
||||
|
@ -82,13 +99,6 @@ abstract class ReleephFieldSpecification
|
|||
}
|
||||
|
||||
|
||||
/* -( Edit View )---------------------------------------------------------- */
|
||||
|
||||
public function renderReleephEditControl(AphrontRequest $request) {
|
||||
throw new ReleephFieldSpecificationIncompleteException($this);
|
||||
}
|
||||
|
||||
|
||||
/* -( Conduit )------------------------------------------------------------ */
|
||||
|
||||
public function getKeyForConduit() {
|
||||
|
|
|
@ -39,16 +39,11 @@ abstract class ReleephLevelFieldSpecification
|
|||
return $this->getNameForLevel($level);
|
||||
}
|
||||
|
||||
public function renderReleephEditControl(AphrontRequest $request) {
|
||||
public function renderEditControl() {
|
||||
$control_name = $this->getRequiredStorageKey();
|
||||
$all_levels = $this->getLevels();
|
||||
|
||||
$level = $request->getStr($control_name);
|
||||
|
||||
if (!$level) {
|
||||
$level = $this->getCanonicalLevel($this->getValue());
|
||||
}
|
||||
|
||||
$level = $this->getCanonicalLevel($this->getValue());
|
||||
if (!$level) {
|
||||
$level = $this->getDefaultLevel();
|
||||
}
|
||||
|
|
|
@ -35,13 +35,12 @@ final class ReleephReasonFieldSpecification
|
|||
|
||||
private $error = true;
|
||||
|
||||
public function renderReleephEditControl(AphrontRequest $request) {
|
||||
$reason = $request->getStr('reason', $this->getValue());
|
||||
public function renderEditControl() {
|
||||
return id(new AphrontFormTextAreaControl())
|
||||
->setLabel('Reason')
|
||||
->setName('reason')
|
||||
->setError($this->error)
|
||||
->setValue($reason);
|
||||
->setValue($this->getValue());
|
||||
}
|
||||
|
||||
public function validate($reason) {
|
||||
|
|
|
@ -19,13 +19,12 @@ final class ReleephSummaryFieldSpecification
|
|||
|
||||
private $error = false;
|
||||
|
||||
public function renderReleephEditControl(AphrontRequest $request) {
|
||||
$summary = $request->getStr('summary', $this->getValue());
|
||||
public function renderEditControl() {
|
||||
return id(new AphrontFormTextControl())
|
||||
->setLabel('Summary')
|
||||
->setName('summary')
|
||||
->setError($this->error)
|
||||
->setValue($summary)
|
||||
->setValue($this->getValue())
|
||||
->setCaption(
|
||||
'Leave this blank to use the original commit title');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue