3 final class PhabricatorCustomFieldSearchEngineExtension
4 extends PhabricatorSearchEngineExtension
{
6 const EXTENSIONKEY
= 'customfield';
8 public function isExtensionEnabled() {
12 public function getExtensionName() {
13 return pht('Support for Custom Fields');
16 public function supportsObject($object) {
17 return ($object instanceof PhabricatorCustomFieldInterface
);
20 public function getExtensionOrder() {
24 public function getSearchFields($object) {
25 $engine = $this->getSearchEngine();
26 $custom_fields = $this->getCustomFields($object);
29 foreach ($custom_fields as $field) {
30 $fields[] = id(new PhabricatorSearchCustomFieldProxyField())
31 ->setSearchEngine($engine)
32 ->setCustomField($field);
38 public function applyConstraintsToQuery(
41 PhabricatorSavedQuery
$saved,
44 $engine = $this->getSearchEngine();
45 $fields = $this->getCustomFields($object);
47 foreach ($fields as $field) {
48 $field->applyApplicationSearchConstraintToQuery(
51 $saved->getParameter('custom:'.$field->getFieldIndex()));
55 private function getCustomFields($object) {
56 $fields = PhabricatorCustomField
::getObjectFields(
58 PhabricatorCustomField
::ROLE_APPLICATIONSEARCH
);
59 $fields->setViewer($this->getViewer());
61 return $fields->getFields();
64 public function getFieldSpecificationsForConduit($object) {
65 $fields = PhabricatorCustomField
::getObjectFields(
67 PhabricatorCustomField
::ROLE_CONDUIT
);
70 foreach ($fields->getFields() as $field) {
71 $key = $field->getModernFieldKey();
73 // TODO: These should have proper types.
74 $map[] = id(new PhabricatorConduitSearchFieldSpecification())
77 ->setDescription($field->getFieldDescription());
83 public function loadExtensionConduitData(array $objects) {
84 $viewer = $this->getViewer();
87 foreach ($objects as $object) {
88 $object_phid = $object->getPHID();
90 $fields = PhabricatorCustomField
::getObjectFields(
92 PhabricatorCustomField
::ROLE_CONDUIT
);
96 ->readFieldsFromObject($object);
98 $field_map[$object_phid] = $fields;
101 $all_fields = array();
102 foreach ($field_map as $field_list) {
103 foreach ($field_list->getFields() as $field) {
104 $all_fields[] = $field;
108 id(new PhabricatorCustomFieldStorageQuery())
109 ->addFields($all_fields)
113 'fields' => $field_map,
117 public function getFieldValuesForConduit($object, $data) {
118 $fields = $data['fields'][$object->getPHID()];
121 foreach ($fields->getFields() as $field) {
122 $key = $field->getModernFieldKey();
123 $map[$key] = $field->getConduitDictionaryValue();