Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / infrastructure / customfield / datasource / PhabricatorStandardSelectCustomFieldDatasource.php
blobfee2c3459672d441708761f3ae45c2a7280887d9
1 <?php
3 final class PhabricatorStandardSelectCustomFieldDatasource
4 extends PhabricatorTypeaheadDatasource {
6 public function getBrowseTitle() {
7 return pht('Browse Values');
10 public function getPlaceholderText() {
11 return pht('Type a field value...');
14 public function getDatasourceApplicationClass() {
15 return null;
18 public function loadResults() {
19 $viewer = $this->getViewer();
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));
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));
39 $role = $this->getParameter('role');
40 if (!strlen($role)) {
41 throw new Exception(pht('No custom field role specified.'));
44 $object = newv($class, array());
45 $field_list = PhabricatorCustomField::getObjectFields($object, $role);
47 $field_key = $this->getParameter('key');
48 if (!strlen($field_key)) {
49 throw new Exception(pht('No custom field key specified.'));
52 $field = null;
53 foreach ($field_list->getFields() as $candidate_field) {
54 if ($candidate_field->getFieldKey() == $field_key) {
55 $field = $candidate_field;
56 break;
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));
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));
81 $options = $field->getOptions();
83 $results = array();
84 foreach ($options as $key => $option) {
85 $results[] = id(new PhabricatorTypeaheadResult())
86 ->setName($option)
87 ->setPHID($key);
90 return $this->filterResultsAgainstTokens($results);