@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
3abstract class PhabricatorEditEngineController
4 extends PhabricatorApplicationTransactionController {
5
6 private $engineKey;
7
8 /**
9 * @param string $engine_key Engine key, e.g. 'maniphest.task'
10 */
11 public function setEngineKey($engine_key) {
12 $this->engineKey = $engine_key;
13 return $this;
14 }
15
16 public function getEngineKey() {
17 return $this->engineKey;
18 }
19
20 protected function buildApplicationCrumbs() {
21 $crumbs = parent::buildApplicationCrumbs();
22
23 $crumbs->addTextCrumb(pht('Edit Engines'), '/transactions/editengine/');
24
25 $engine_key = $this->getEngineKey();
26 if ($engine_key !== null) {
27 $engine = PhabricatorEditEngine::getByKey(
28 $this->getViewer(),
29 $engine_key);
30 if ($engine) {
31 $crumbs->addTextCrumb(
32 $engine->getEngineName(),
33 "/transactions/editengine/{$engine_key}/");
34 }
35 }
36
37 return $crumbs;
38 }
39
40 /**
41 * @return PhabricatorEditEngineConfiguration|null
42 */
43 protected function loadConfigForEdit() {
44 return $this->loadConfig($need_edit = true);
45 }
46
47 /**
48 * @return PhabricatorEditEngineConfiguration|null
49 */
50 protected function loadConfigForView() {
51 return $this->loadConfig($need_edit = false);
52 }
53
54 /**
55 * @param bool $need_edit
56 * @return PhabricatorEditEngineConfiguration|null
57 */
58 private function loadConfig($need_edit) {
59 $request = $this->getRequest();
60 $viewer = $this->getViewer();
61
62 $engine_key = $request->getURIData('engineKey');
63 $this->setEngineKey($engine_key);
64
65 $key = $request->getURIData('key');
66
67 if ($need_edit) {
68 $capabilities = array(
69 PhabricatorPolicyCapability::CAN_VIEW,
70 PhabricatorPolicyCapability::CAN_EDIT,
71 );
72 } else {
73 $capabilities = array(
74 PhabricatorPolicyCapability::CAN_VIEW,
75 );
76 }
77
78 $config = id(new PhabricatorEditEngineConfigurationQuery())
79 ->setViewer($viewer)
80 ->withEngineKeys(array($engine_key))
81 ->withIdentifiers(array($key))
82 ->requireCapabilities($capabilities)
83 ->executeOne();
84 if ($config) {
85 $engine = $config->getEngine();
86 } else {
87 return null;
88 }
89
90 if (!$engine->isEngineConfigurable()) {
91 return null;
92 }
93
94 return $config;
95 }
96
97
98}