@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhabricatorSpacesSearchEngineExtension
4 extends PhabricatorSearchEngineExtension {
5
6 const EXTENSIONKEY = 'spaces';
7
8 public function isExtensionEnabled() {
9 return PhabricatorApplication::isClassInstalled(
10 PhabricatorSpacesApplication::class);
11 }
12
13 public function getExtensionName() {
14 return pht('Support for Spaces');
15 }
16
17 public function getExtensionOrder() {
18 return 4000;
19 }
20
21 public function supportsObject($object) {
22 return ($object instanceof PhabricatorSpacesInterface);
23 }
24
25 public function getSearchFields($object) {
26 $fields = array();
27
28 if (PhabricatorSpacesNamespaceQuery::getSpacesExist()) {
29 $fields[] = id(new PhabricatorSpacesSearchField())
30 ->setKey('spacePHIDs')
31 ->setConduitKey('spaces')
32 ->setAliases(array('space', 'spaces'))
33 ->setLabel(pht('Spaces'))
34 ->setDescription(
35 pht('Search for objects in certain spaces.'));
36 }
37
38 return $fields;
39 }
40
41 public function applyConstraintsToQuery(
42 $object,
43 $query,
44 PhabricatorSavedQuery $saved,
45 array $map) {
46
47 if (!empty($map['spacePHIDs'])) {
48 $query->withSpacePHIDs($map['spacePHIDs']);
49 } else {
50 // If the user doesn't search for objects in specific spaces, we
51 // default to "all active spaces you have permission to view".
52 $query->withSpaceIsArchived(false);
53 }
54 }
55
56 public function getFieldSpecificationsForConduit($object) {
57 return array(
58 id(new PhabricatorConduitSearchFieldSpecification())
59 ->setKey('spacePHID')
60 ->setType('phid?')
61 ->setDescription(
62 pht('PHID of the policy space this object is part of.')),
63 );
64 }
65
66 public function getFieldValuesForConduit($object, $data) {
67 return array(
68 'spacePHID' => $object->getSpacePHID(),
69 );
70 }
71
72}