Skip to content

Commit ed7a507

Browse files
author
epriestley
committed
Add "user" and "users" standard custom fields
Summary: These end up a little weird with subclassing instead of `switch`, but some day we could alias them to one another or something I guess. If I'm feeling brave, I might get rid of the "user" variant when I migrate Maniphest custom field specs, and turn it into "users, limit = 1" or something like that. Test Plan: See screenshots. Reviewers: btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D7010
1 parent 6115670 commit ed7a507

File tree

5 files changed

+147
-2
lines changed

5 files changed

+147
-2
lines changed

src/__phutil_library_map__.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,9 +1640,11 @@
16401640
'PhabricatorStandardCustomFieldDate' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php',
16411641
'PhabricatorStandardCustomFieldInt' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php',
16421642
'PhabricatorStandardCustomFieldInterface' => 'infrastructure/customfield/interface/PhabricatorStandardCustomFieldInterface.php',
1643+
'PhabricatorStandardCustomFieldPHIDs' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldPHIDs.php',
16431644
'PhabricatorStandardCustomFieldRemarkup' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldRemarkup.php',
16441645
'PhabricatorStandardCustomFieldSelect' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php',
16451646
'PhabricatorStandardCustomFieldText' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldText.php',
1647+
'PhabricatorStandardCustomFieldUsers' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldUsers.php',
16461648
'PhabricatorStandardPageView' => 'view/page/PhabricatorStandardPageView.php',
16471649
'PhabricatorStatusController' => 'applications/system/PhabricatorStatusController.php',
16481650
'PhabricatorStorageFixtureScopeGuard' => 'infrastructure/testing/fixture/PhabricatorStorageFixtureScopeGuard.php',
@@ -3792,9 +3794,11 @@
37923794
'PhabricatorStandardCustomFieldBool' => 'PhabricatorStandardCustomField',
37933795
'PhabricatorStandardCustomFieldDate' => 'PhabricatorStandardCustomField',
37943796
'PhabricatorStandardCustomFieldInt' => 'PhabricatorStandardCustomField',
3797+
'PhabricatorStandardCustomFieldPHIDs' => 'PhabricatorStandardCustomField',
37953798
'PhabricatorStandardCustomFieldRemarkup' => 'PhabricatorStandardCustomField',
37963799
'PhabricatorStandardCustomFieldSelect' => 'PhabricatorStandardCustomField',
37973800
'PhabricatorStandardCustomFieldText' => 'PhabricatorStandardCustomField',
3801+
'PhabricatorStandardCustomFieldUsers' => 'PhabricatorStandardCustomFieldPHIDs',
37983802
'PhabricatorStandardPageView' => 'PhabricatorBarePageView',
37993803
'PhabricatorStatusController' => 'PhabricatorController',
38003804
'PhabricatorStorageManagementDatabasesWorkflow' => 'PhabricatorStorageManagementWorkflow',

src/applications/people/query/PhabricatorPeopleQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ public function loadPage() {
105105
$table->getTableName(),
106106
$this->buildJoinsClause($conn_r),
107107
$this->buildWhereClause($conn_r),
108-
$this->buildOrderClause($conn_r),
109108
$this->buildApplicationSearchGroupClause($conn_r),
109+
$this->buildOrderClause($conn_r),
110110
$this->buildLimitClause($conn_r));
111111

112112
if ($this->needPrimaryEmail) {

src/applications/search/engine/PhabricatorApplicationSearchEngine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ protected function appendCustomFieldsToForm(
504504
$handles = array();
505505
if ($all_phids) {
506506
$handles = id(new PhabricatorHandleQuery())
507-
->setViewer($this->getViewer())
507+
->setViewer($this->requireViewer())
508508
->withPHIDs($all_phids)
509509
->execute();
510510
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
/**
4+
* Common code for standard field types which store lists of PHIDs.
5+
*/
6+
abstract class PhabricatorStandardCustomFieldPHIDs
7+
extends PhabricatorStandardCustomField {
8+
9+
public function buildFieldIndexes() {
10+
$indexes = array();
11+
12+
$value = $this->getFieldValue();
13+
if (is_array($value)) {
14+
foreach ($value as $phid) {
15+
$indexes[] = $this->newStringIndex($phid);
16+
}
17+
}
18+
19+
return $indexes;
20+
}
21+
22+
public function readValueFromRequest(AphrontRequest $request) {
23+
$value = $request->getArr($this->getFieldKey());
24+
$this->setFieldValue($value);
25+
}
26+
27+
public function getValueForStorage() {
28+
$value = $this->getFieldValue();
29+
if (!$value) {
30+
return null;
31+
}
32+
33+
return json_encode(array_values($value));
34+
}
35+
36+
public function setValueFromStorage($value) {
37+
$result = array();
38+
if ($value) {
39+
$value = json_decode($value, true);
40+
if (is_array($value)) {
41+
$result = array_values($value);
42+
}
43+
}
44+
$this->setFieldValue($value);
45+
}
46+
47+
public function readApplicationSearchValueFromRequest(
48+
PhabricatorApplicationSearchEngine $engine,
49+
AphrontRequest $request) {
50+
return $request->getArr($this->getFieldKey());
51+
}
52+
53+
public function applyApplicationSearchConstraintToQuery(
54+
PhabricatorApplicationSearchEngine $engine,
55+
PhabricatorCursorPagedPolicyAwareQuery $query,
56+
$value) {
57+
if ($value) {
58+
$query->withApplicationSearchContainsConstraint(
59+
$this->newStringIndex(null),
60+
$value);
61+
}
62+
}
63+
64+
public function getRequiredHandlePHIDsForApplicationSearch($value) {
65+
if ($value) {
66+
return $value;
67+
}
68+
return array();
69+
}
70+
71+
public function renderPropertyViewValue() {
72+
$value = $this->getFieldValue();
73+
if (!$value) {
74+
return null;
75+
}
76+
77+
// TODO: Surface and batch this.
78+
79+
$handles = id(new PhabricatorHandleQuery())
80+
->setViewer($this->getViewer())
81+
->withPHIDs($value)
82+
->execute();
83+
84+
$handles = mpull($handles, 'renderLink');
85+
$handles = phutil_implode_html(', ', $handles);
86+
return $handles;
87+
}
88+
89+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
final class PhabricatorStandardCustomFieldUsers
4+
extends PhabricatorStandardCustomFieldPHIDs {
5+
6+
public function getFieldType() {
7+
return 'users';
8+
}
9+
10+
public function renderEditControl() {
11+
$handles = array();
12+
$value = $this->getFieldValue();
13+
if ($value) {
14+
15+
// TODO: Surface and batch.
16+
17+
$handles = id(new PhabricatorHandleQuery())
18+
->setViewer($this->getViewer())
19+
->withPHIDs($value)
20+
->execute();
21+
}
22+
23+
$control = id(new AphrontFormTokenizerControl())
24+
->setLabel($this->getFieldName())
25+
->setName($this->getFieldKey())
26+
->setDatasource('/typeahead/common/accounts/')
27+
->setValue($handles);
28+
29+
$limit = $this->getFieldConfigValue('limit');
30+
if ($limit) {
31+
$control->setLimit($limit);
32+
}
33+
34+
return $control;
35+
}
36+
37+
public function appendToApplicationSearchForm(
38+
PhabricatorApplicationSearchEngine $engine,
39+
AphrontFormView $form,
40+
$value,
41+
array $handles) {
42+
43+
$control = id(new AphrontFormTokenizerControl())
44+
->setLabel($this->getFieldName())
45+
->setName($this->getFieldKey())
46+
->setDatasource('/typeahead/common/accounts/')
47+
->setValue($handles);
48+
49+
$form->appendChild($control);
50+
}
51+
52+
}

0 commit comments

Comments
 (0)