Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/infrastructure/customfield/datasource/PhabricatorStandardSelectCustomFieldDatasource.php
12242 views
1
<?php
2
3
final class PhabricatorStandardSelectCustomFieldDatasource
4
extends PhabricatorTypeaheadDatasource {
5
6
public function getBrowseTitle() {
7
return pht('Browse Values');
8
}
9
10
public function getPlaceholderText() {
11
return pht('Type a field value...');
12
}
13
14
public function getDatasourceApplicationClass() {
15
return null;
16
}
17
18
public function loadResults() {
19
$viewer = $this->getViewer();
20
21
$class = $this->getParameter('object');
22
if (!class_exists($class)) {
23
throw new Exception(
24
pht(
25
'Custom field class "%s" does not exist.',
26
$class));
27
}
28
29
$reflection = new ReflectionClass($class);
30
$interface = 'PhabricatorCustomFieldInterface';
31
if (!$reflection->implementsInterface($interface)) {
32
throw new Exception(
33
pht(
34
'Custom field class "%s" does not implement interface "%s".',
35
$class,
36
$interface));
37
}
38
39
$role = $this->getParameter('role');
40
if (!strlen($role)) {
41
throw new Exception(pht('No custom field role specified.'));
42
}
43
44
$object = newv($class, array());
45
$field_list = PhabricatorCustomField::getObjectFields($object, $role);
46
47
$field_key = $this->getParameter('key');
48
if (!strlen($field_key)) {
49
throw new Exception(pht('No custom field key specified.'));
50
}
51
52
$field = null;
53
foreach ($field_list->getFields() as $candidate_field) {
54
if ($candidate_field->getFieldKey() == $field_key) {
55
$field = $candidate_field;
56
break;
57
}
58
}
59
60
if ($field === null) {
61
throw new Exception(
62
pht(
63
'No field with field key "%s" exists for objects of class "%s" with '.
64
'custom field role "%s".',
65
$field_key,
66
$class,
67
$role));
68
}
69
70
if (!($field instanceof PhabricatorStandardCustomFieldSelect)) {
71
$field = $field->getProxy();
72
if (!($field instanceof PhabricatorStandardCustomFieldSelect)) {
73
throw new Exception(
74
pht(
75
'Field "%s" is not a standard select field, nor a proxy of a '.
76
'standard select field.',
77
$field_key));
78
}
79
}
80
81
$options = $field->getOptions();
82
83
$results = array();
84
foreach ($options as $key => $option) {
85
$results[] = id(new PhabricatorTypeaheadResult())
86
->setName($option)
87
->setPHID($key);
88
}
89
90
return $this->filterResultsAgainstTokens($results);
91
}
92
93
}
94
95