Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / infrastructure / customfield / engineextension / PhabricatorCustomFieldSearchEngineExtension.php
blob309e3d2949d9a79696cdb70eeff96a0b0e88f0cf
1 <?php
3 final class PhabricatorCustomFieldSearchEngineExtension
4 extends PhabricatorSearchEngineExtension {
6 const EXTENSIONKEY = 'customfield';
8 public function isExtensionEnabled() {
9 return true;
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() {
21 return 9000;
24 public function getSearchFields($object) {
25 $engine = $this->getSearchEngine();
26 $custom_fields = $this->getCustomFields($object);
28 $fields = array();
29 foreach ($custom_fields as $field) {
30 $fields[] = id(new PhabricatorSearchCustomFieldProxyField())
31 ->setSearchEngine($engine)
32 ->setCustomField($field);
35 return $fields;
38 public function applyConstraintsToQuery(
39 $object,
40 $query,
41 PhabricatorSavedQuery $saved,
42 array $map) {
44 $engine = $this->getSearchEngine();
45 $fields = $this->getCustomFields($object);
47 foreach ($fields as $field) {
48 $field->applyApplicationSearchConstraintToQuery(
49 $engine,
50 $query,
51 $saved->getParameter('custom:'.$field->getFieldIndex()));
55 private function getCustomFields($object) {
56 $fields = PhabricatorCustomField::getObjectFields(
57 $object,
58 PhabricatorCustomField::ROLE_APPLICATIONSEARCH);
59 $fields->setViewer($this->getViewer());
61 return $fields->getFields();
64 public function getFieldSpecificationsForConduit($object) {
65 $fields = PhabricatorCustomField::getObjectFields(
66 $object,
67 PhabricatorCustomField::ROLE_CONDUIT);
69 $map = array();
70 foreach ($fields->getFields() as $field) {
71 $key = $field->getModernFieldKey();
73 // TODO: These should have proper types.
74 $map[] = id(new PhabricatorConduitSearchFieldSpecification())
75 ->setKey($key)
76 ->setType('wild')
77 ->setDescription($field->getFieldDescription());
80 return $map;
83 public function loadExtensionConduitData(array $objects) {
84 $viewer = $this->getViewer();
86 $field_map = array();
87 foreach ($objects as $object) {
88 $object_phid = $object->getPHID();
90 $fields = PhabricatorCustomField::getObjectFields(
91 $object,
92 PhabricatorCustomField::ROLE_CONDUIT);
94 $fields
95 ->setViewer($viewer)
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)
110 ->execute();
112 return array(
113 'fields' => $field_map,
117 public function getFieldValuesForConduit($object, $data) {
118 $fields = $data['fields'][$object->getPHID()];
120 $map = array();
121 foreach ($fields->getFields() as $field) {
122 $key = $field->getModernFieldKey();
123 $map[$key] = $field->getConduitDictionaryValue();
126 return $map;