From 77c03a8a42afa6322288783d57a80abda6e883be Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 7 Jun 2013 10:22:45 -0700 Subject: [PATCH] Add "Title" and "Blurb" to new profile editor Summary: Ref T1703. - Adds "Title". - Adds "Blurb". - Adds `user.fields` config for selecting and reordering. This will get UI in the next patch. Test Plan: {F45689} {F45690} Edited the fields, too. Reviewers: chad Reviewed By: chad CC: aran Maniphest Tasks: T1703 Differential Revision: https://secure.phabricator.com/D6153 --- src/__phutil_library_map__.php | 6 +++ .../config/PhabricatorUserConfigOptions.php | 34 +++++++++++++ .../customfield/PhabricatorUserBlurbField.php | 48 ++++++++++++++++++ .../customfield/PhabricatorUserTitleField.php | 49 +++++++++++++++++++ .../people/storage/PhabricatorUser.php | 7 ++- 5 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 src/applications/people/config/PhabricatorUserConfigOptions.php create mode 100644 src/applications/people/customfield/PhabricatorUserBlurbField.php create mode 100644 src/applications/people/customfield/PhabricatorUserTitleField.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 6a63e4d36f..c6de741894 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1544,6 +1544,8 @@ phutil_register_library_map(array( 'PhabricatorUITooltipExample' => 'applications/uiexample/examples/PhabricatorUITooltipExample.php', 'PhabricatorUnitsTestCase' => 'view/__tests__/PhabricatorUnitsTestCase.php', 'PhabricatorUser' => 'applications/people/storage/PhabricatorUser.php', + 'PhabricatorUserBlurbField' => 'applications/people/customfield/PhabricatorUserBlurbField.php', + 'PhabricatorUserConfigOptions' => 'applications/people/config/PhabricatorUserConfigOptions.php', 'PhabricatorUserCustomField' => 'applications/people/customfield/PhabricatorUserCustomField.php', 'PhabricatorUserCustomFieldInterface' => 'applications/people/customfield/PhabricatorUserCustomFieldInterface.php', 'PhabricatorUserDAO' => 'applications/people/storage/PhabricatorUserDAO.php', @@ -1562,6 +1564,7 @@ phutil_register_library_map(array( 'PhabricatorUserStatusInvalidEpochException' => 'applications/people/exception/PhabricatorUserStatusInvalidEpochException.php', 'PhabricatorUserStatusOverlapException' => 'applications/people/exception/PhabricatorUserStatusOverlapException.php', 'PhabricatorUserTestCase' => 'applications/people/storage/__tests__/PhabricatorUserTestCase.php', + 'PhabricatorUserTitleField' => 'applications/people/customfield/PhabricatorUserTitleField.php', 'PhabricatorUserTransaction' => 'applications/people/storage/PhabricatorUserTransaction.php', 'PhabricatorWorkboardExample' => 'applications/uiexample/examples/PhabricatorWorkboardExample.php', 'PhabricatorWorkboardView' => 'view/layout/PhabricatorWorkboardView.php', @@ -3385,6 +3388,8 @@ phutil_register_library_map(array( 2 => 'PhabricatorPolicyInterface', 3 => 'PhabricatorCustomFieldInterface', ), + 'PhabricatorUserBlurbField' => 'PhabricatorUserCustomField', + 'PhabricatorUserConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorUserCustomField' => array( 0 => 'PhabricatorCustomField', @@ -3406,6 +3411,7 @@ phutil_register_library_map(array( 'PhabricatorUserStatusInvalidEpochException' => 'Exception', 'PhabricatorUserStatusOverlapException' => 'Exception', 'PhabricatorUserTestCase' => 'PhabricatorTestCase', + 'PhabricatorUserTitleField' => 'PhabricatorUserCustomField', 'PhabricatorUserTransaction' => 'PhabricatorApplicationTransaction', 'PhabricatorWorkboardExample' => 'PhabricatorUIExample', 'PhabricatorWorkboardView' => 'AphrontView', diff --git a/src/applications/people/config/PhabricatorUserConfigOptions.php b/src/applications/people/config/PhabricatorUserConfigOptions.php new file mode 100644 index 0000000000..c23a78e279 --- /dev/null +++ b/src/applications/people/config/PhabricatorUserConfigOptions.php @@ -0,0 +1,34 @@ +getFieldKey() => true, + id(new PhabricatorUserTitleField())->getFieldKey() => true, + id(new PhabricatorUserBlurbField())->getFieldKey() => true, + ); + + foreach ($default as $key => $enabled) { + $default[$key] = array( + 'disabled' => !$enabled, + ); + } + + return array( + $this->newOption('user.fields', 'wild', $default) + ->setDescription(pht("Select and reorder user profile fields.")), + ); + } + +} diff --git a/src/applications/people/customfield/PhabricatorUserBlurbField.php b/src/applications/people/customfield/PhabricatorUserBlurbField.php new file mode 100644 index 0000000000..67973a8b23 --- /dev/null +++ b/src/applications/people/customfield/PhabricatorUserBlurbField.php @@ -0,0 +1,48 @@ +value = $object->loadUserProfile()->getBlurb(); + } + + public function getOldValueForApplicationTransactions() { + return $this->getObject()->loadUserProfile()->getBlurb(); + } + + public function getNewValueForApplicationTransactions() { + return $this->value; + } + + public function applyApplicationTransactionInternalEffects( + PhabricatorApplicationTransaction $xaction) { + $this->getObject()->loadUserProfile()->setBlurb($xaction->getNewValue()); + } + + public function setValueFromRequest(AphrontRequest $request) { + $this->value = $request->getStr($this->getFieldKey()); + } + + public function renderEditControl() { + return id(new PhabricatorRemarkupControl()) + ->setName($this->getFieldKey()) + ->setValue($this->value) + ->setLabel($this->getFieldName()); + } + +} diff --git a/src/applications/people/customfield/PhabricatorUserTitleField.php b/src/applications/people/customfield/PhabricatorUserTitleField.php new file mode 100644 index 0000000000..5e9fe2c65e --- /dev/null +++ b/src/applications/people/customfield/PhabricatorUserTitleField.php @@ -0,0 +1,49 @@ +value = $object->loadUserProfile()->getTitle(); + } + + public function getOldValueForApplicationTransactions() { + return $this->getObject()->loadUserProfile()->getTitle(); + } + + public function getNewValueForApplicationTransactions() { + return $this->value; + } + + public function applyApplicationTransactionInternalEffects( + PhabricatorApplicationTransaction $xaction) { + $this->getObject()->loadUserProfile()->setTitle($xaction->getNewValue()); + } + + public function setValueFromRequest(AphrontRequest $request) { + $this->value = $request->getStr($this->getFieldKey()); + } + + public function renderEditControl() { + return id(new AphrontFormTextControl()) + ->setName($this->getFieldKey()) + ->setValue($this->value) + ->setLabel($this->getFieldName()) + ->setCaption(pht('Serious business title.')); + } + +} diff --git a/src/applications/people/storage/PhabricatorUser.php b/src/applications/people/storage/PhabricatorUser.php index b481971c0c..16016a3be5 100644 --- a/src/applications/people/storage/PhabricatorUser.php +++ b/src/applications/people/storage/PhabricatorUser.php @@ -113,6 +113,10 @@ final class PhabricatorUser } $result = parent::save(); + if ($this->profile) { + $this->profile->save(); + } + $this->updateNameTokens(); id(new PhabricatorSearchIndexer()) @@ -764,8 +768,7 @@ EOBODY; public function getCustomFieldSpecificationForRole($role) { - return array(); - // TODO: PhabricatorEnv::getEnvConfig('user.fields'); + return PhabricatorEnv::getEnvConfig('user.fields'); } public function getCustomFieldBaseClass() {