Simplify and improve PhabricatorCustomField APIs

Summary:
Ref T1703. Ref T3718. The `PhabricatorCustomFieldList` seems like a pretty good idea. Move more code into it to make it harder to get wrong.

Also the sequencing on old/new values for these transactions was a bit off; fix that up.

Test Plan: Edited standard and custom profile fields.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1703, T3718

Differential Revision: https://secure.phabricator.com/D6751
This commit is contained in:
epriestley
2013-08-14 09:40:42 -07:00
parent 74de24909b
commit 938b63aaa9
7 changed files with 57 additions and 28 deletions

View File

@@ -97,10 +97,9 @@ final class PhabricatorPeopleProfileController
->setUser($viewer)
->setObject($user);
$fields = PhabricatorCustomField::getObjectFields(
$field_list = PhabricatorCustomField::getObjectFields(
$user,
PhabricatorCustomField::ROLE_VIEW);
$field_list = new PhabricatorCustomFieldList($fields);
$field_list->appendFieldsToPropertyList($user, $viewer, $view);
return $view;

View File

@@ -32,20 +32,15 @@ final class PhabricatorPeopleProfileEditController
$profile_uri = '/p/'.$user->getUsername().'/';
$fields = PhabricatorCustomField::getObjectFields(
$field_list = PhabricatorCustomField::getObjectFields(
$user,
PhabricatorCustomField::ROLE_EDIT);
$field_list = new PhabricatorCustomFieldList($fields);
$field_list->readFieldsFromStorage($user);
if ($request->isFormPost()) {
$xactions = array();
foreach ($fields as $field) {
$field->readValueFromRequest($request);
$xactions[] = id(new PhabricatorUserTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_CUSTOMFIELD)
->setMetadataValue('customfield:key', $field->getFieldKey())
->setNewValue($field->getNewValueForApplicationTransactions());
}
$xactions = $field_list->buildFieldTransactionsFromRequest(
new PhabricatorUserTransaction(),
$request);
$editor = id(new PhabricatorUserProfileEditor())
->setActor($viewer)
@@ -56,8 +51,6 @@ final class PhabricatorPeopleProfileEditController
$editor->applyTransactions($user, $xactions);
return id(new AphrontRedirectResponse())->setURI($profile_uri);
} else {
$field_list->readFieldsFromStorage($user);
}
$title = pht('Edit Profile');