1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 16:52:41 +01:00

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
This commit is contained in:
epriestley 2013-06-07 10:22:45 -07:00
parent 6ffbee115b
commit 77c03a8a42
5 changed files with 142 additions and 2 deletions

View file

@ -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',

View file

@ -0,0 +1,34 @@
<?php
final class PhabricatorUserConfigOptions
extends PhabricatorApplicationConfigOptions {
public function getName() {
return pht("User Profiles");
}
public function getDescription() {
return pht("User profiles configuration.");
}
public function getOptions() {
$default = array(
id(new PhabricatorUserRealNameField())->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.")),
);
}
}

View file

@ -0,0 +1,48 @@
<?php
final class PhabricatorUserBlurbField
extends PhabricatorUserCustomField {
private $value;
public function getFieldKey() {
return 'user:blurb';
}
public function getFieldName() {
return pht('Blurb');
}
public function getFieldDescription() {
return pht('Short user summary.');
}
protected function didSetObject(PhabricatorCustomFieldInterface $object) {
$this->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());
}
}

View file

@ -0,0 +1,49 @@
<?php
final class PhabricatorUserTitleField
extends PhabricatorUserCustomField {
private $value;
public function getFieldKey() {
return 'user:title';
}
public function getFieldName() {
return pht('Title');
}
public function getFieldDescription() {
return pht('User title, like "CEO" or "Assistant to the Manager".');
}
protected function didSetObject(PhabricatorCustomFieldInterface $object) {
$this->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.'));
}
}

View file

@ -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() {