Path: blob/master/src/infrastructure/customfield/datasource/PhabricatorStandardSelectCustomFieldDatasource.php
12242 views
<?php12final class PhabricatorStandardSelectCustomFieldDatasource3extends PhabricatorTypeaheadDatasource {45public function getBrowseTitle() {6return pht('Browse Values');7}89public function getPlaceholderText() {10return pht('Type a field value...');11}1213public function getDatasourceApplicationClass() {14return null;15}1617public function loadResults() {18$viewer = $this->getViewer();1920$class = $this->getParameter('object');21if (!class_exists($class)) {22throw new Exception(23pht(24'Custom field class "%s" does not exist.',25$class));26}2728$reflection = new ReflectionClass($class);29$interface = 'PhabricatorCustomFieldInterface';30if (!$reflection->implementsInterface($interface)) {31throw new Exception(32pht(33'Custom field class "%s" does not implement interface "%s".',34$class,35$interface));36}3738$role = $this->getParameter('role');39if (!strlen($role)) {40throw new Exception(pht('No custom field role specified.'));41}4243$object = newv($class, array());44$field_list = PhabricatorCustomField::getObjectFields($object, $role);4546$field_key = $this->getParameter('key');47if (!strlen($field_key)) {48throw new Exception(pht('No custom field key specified.'));49}5051$field = null;52foreach ($field_list->getFields() as $candidate_field) {53if ($candidate_field->getFieldKey() == $field_key) {54$field = $candidate_field;55break;56}57}5859if ($field === null) {60throw new Exception(61pht(62'No field with field key "%s" exists for objects of class "%s" with '.63'custom field role "%s".',64$field_key,65$class,66$role));67}6869if (!($field instanceof PhabricatorStandardCustomFieldSelect)) {70$field = $field->getProxy();71if (!($field instanceof PhabricatorStandardCustomFieldSelect)) {72throw new Exception(73pht(74'Field "%s" is not a standard select field, nor a proxy of a '.75'standard select field.',76$field_key));77}78}7980$options = $field->getOptions();8182$results = array();83foreach ($options as $key => $option) {84$results[] = id(new PhabricatorTypeaheadResult())85->setName($option)86->setPHID($key);87}8889return $this->filterResultsAgainstTokens($results);90}9192}939495