@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 PhabricatorEditEngineConfigurationSearchEngine
4 extends PhabricatorApplicationSearchEngine {
5
6 private $engineKey;
7
8 public function setEngineKey($engine_key) {
9 $this->engineKey = $engine_key;
10 return $this;
11 }
12
13 public function getEngineKey() {
14 return $this->engineKey;
15 }
16
17 public function canUseInPanelContext() {
18 return false;
19 }
20
21 public function getResultTypeDescription() {
22 return pht('Forms');
23 }
24
25 public function getApplicationClassName() {
26 return PhabricatorTransactionsApplication::class;
27 }
28
29 public function newQuery() {
30 return id(new PhabricatorEditEngineConfigurationQuery())
31 ->withEngineKeys(array($this->getEngineKey()));
32 }
33
34 protected function buildQueryFromParameters(array $map) {
35 $query = $this->newQuery();
36
37 $is_create = $map['isCreate'];
38 if ($is_create !== null) {
39 $query->withIsDefault($is_create);
40 }
41
42 $is_edit = $map['isEdit'];
43 if ($is_edit !== null) {
44 $query->withIsEdit($is_edit);
45 }
46
47 return $query;
48 }
49
50 protected function buildCustomSearchFields() {
51 return array(
52 id(new PhabricatorSearchThreeStateField())
53 ->setLabel(pht('Create'))
54 ->setKey('isCreate')
55 ->setOptions(
56 pht('Show All'),
57 pht('Hide Create Forms'),
58 pht('Show Only Create Forms')),
59 id(new PhabricatorSearchThreeStateField())
60 ->setLabel(pht('Edit'))
61 ->setKey('isEdit')
62 ->setOptions(
63 pht('Show All'),
64 pht('Hide Edit Forms'),
65 pht('Show Only Edit Forms')),
66 );
67 }
68
69 protected function getDefaultFieldOrder() {
70 return array();
71 }
72
73 protected function getURI($path) {
74 return '/transactions/editengine/'.$this->getEngineKey().'/'.$path;
75 }
76
77 protected function getBuiltinQueryNames() {
78 $names = array(
79 'all' => pht('All Forms'),
80 'create' => pht('Create Forms'),
81 'modify' => pht('Edit Forms'),
82 );
83
84 return $names;
85 }
86
87 public function buildSavedQueryFromBuiltin($query_key) {
88 $query = $this->newSavedQuery();
89 $query->setQueryKey($query_key);
90
91 switch ($query_key) {
92 case 'all':
93 return $query;
94 case 'create':
95 return $query->setParameter('isCreate', true);
96 case 'modify':
97 return $query->setParameter('isEdit', true);
98 }
99
100 return parent::buildSavedQueryFromBuiltin($query_key);
101 }
102
103 /**
104 * @param array<PhabricatorEditEngineConfiguration> $configs
105 * @param PhabricatorSavedQuery $query
106 * @param array<PhabricatorObjectHandle> $handles
107 */
108 protected function renderResultList(
109 array $configs,
110 PhabricatorSavedQuery $query,
111 array $handles) {
112 assert_instances_of($configs, PhabricatorEditEngineConfiguration::class);
113 $viewer = $this->requireViewer();
114 $engine_key = $this->getEngineKey();
115
116 $list = id(new PHUIObjectItemListView())
117 ->setUser($viewer);
118 foreach ($configs as $config) {
119 $item = id(new PHUIObjectItemView())
120 ->setHeader($config->getDisplayName());
121
122 $id = $config->getID();
123
124 if ($config->getIsDefault()) {
125 $item->addAttribute(pht('Default Create Form'));
126 }
127
128 if ($config->getIsEdit()) {
129 $item->addAttribute(pht('Edit Form'));
130 }
131
132 if ($config->getIsDisabled()) {
133 $item->setDisabled(true);
134 $item->setStatusIcon('fa-ban grey', pht('Disabled'));
135 } else {
136 $item->setStatusIcon('fa-file-text-o green', pht('Enabled'));
137 }
138
139 $subtype_key = $config->getSubtype();
140 if ($subtype_key !== PhabricatorEditEngineSubtype::SUBTYPE_DEFAULT) {
141 $engine = $config->getEngine();
142 if ($engine->supportsSubtypes()) {
143 $map = $engine->newSubtypeMap();
144 if ($map->isValidSubtype($subtype_key)) {
145 $subtype = $map->getSubtype($subtype_key);
146
147 $icon = $subtype->getIcon();
148 $color = $subtype->getColor();
149
150 $item->addIcon("{$icon} {$color}", $subtype->getName());
151 }
152 }
153 }
154
155 if ($id) {
156 $item->setObjectName(pht('Form %d', $id));
157 $key = $id;
158 } else {
159 $item->addIcon('fa-file-text bluegrey', pht('Builtin'));
160 $key = $config->getBuiltinKey();
161 }
162 $item->setHref("/transactions/editengine/{$engine_key}/view/{$key}/");
163
164 $list->addItem($item);
165 }
166
167 return id(new PhabricatorApplicationSearchResultView())
168 ->setObjectList($list);
169 }
170}