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() {
18 public function loadResults() {
19 $viewer = $this->getViewer();
21 $class = $this->getParameter('object');
22 if (!class_exists($class)) {
25 'Custom field class "%s" does not exist.',
29 $reflection = new ReflectionClass($class);
30 $interface = 'PhabricatorCustomFieldInterface';
31 if (!$reflection->implementsInterface($interface)) {
34 'Custom field class "%s" does not implement interface "%s".',
39 $role = $this->getParameter('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.'));
53 foreach ($field_list->getFields() as $candidate_field) {
54 if ($candidate_field->getFieldKey() == $field_key) {
55 $field = $candidate_field;
60 if ($field === null) {
63 'No field with field key "%s" exists for objects of class "%s" with '.
64 'custom field role "%s".',
70 if (!($field instanceof PhabricatorStandardCustomFieldSelect
)) {
71 $field = $field->getProxy();
72 if (!($field instanceof PhabricatorStandardCustomFieldSelect
)) {
75 'Field "%s" is not a standard select field, nor a proxy of a '.
76 'standard select field.',
81 $options = $field->getOptions();
84 foreach ($options as $key => $option) {
85 $results[] = id(new PhabricatorTypeaheadResult())
90 return $this->filterResultsAgainstTokens($results);