Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/almanac/editor/AlmanacBindingEditEngine.php
12256 views
1
<?php
2
3
final class AlmanacBindingEditEngine
4
extends PhabricatorEditEngine {
5
6
const ENGINECONST = 'almanac.binding';
7
8
private $service;
9
10
public function setService(AlmanacService $service) {
11
$this->service = $service;
12
return $this;
13
}
14
15
public function getService() {
16
if (!$this->service) {
17
throw new PhutilInvalidStateException('setService');
18
}
19
return $this->service;
20
}
21
22
public function isEngineConfigurable() {
23
return false;
24
}
25
26
public function getEngineName() {
27
return pht('Almanac Bindings');
28
}
29
30
public function getSummaryHeader() {
31
return pht('Edit Almanac Binding Configurations');
32
}
33
34
public function getSummaryText() {
35
return pht('This engine is used to edit Almanac bindings.');
36
}
37
38
public function getEngineApplicationClass() {
39
return 'PhabricatorAlmanacApplication';
40
}
41
42
protected function newEditableObject() {
43
$service = $this->getService();
44
return AlmanacBinding::initializeNewBinding($service);
45
}
46
47
protected function newEditableObjectForDocumentation() {
48
$service_type = AlmanacCustomServiceType::SERVICETYPE;
49
$service = AlmanacService::initializeNewService($service_type);
50
$this->setService($service);
51
return $this->newEditableObject();
52
}
53
54
protected function newEditableObjectFromConduit(array $raw_xactions) {
55
$service_phid = null;
56
foreach ($raw_xactions as $raw_xaction) {
57
if ($raw_xaction['type'] !== 'service') {
58
continue;
59
}
60
61
$service_phid = $raw_xaction['value'];
62
}
63
64
if ($service_phid === null) {
65
throw new Exception(
66
pht(
67
'When creating a new Almanac binding via the Conduit API, you '.
68
'must provide a "service" transaction to select a service to bind.'));
69
}
70
71
$service = id(new AlmanacServiceQuery())
72
->setViewer($this->getViewer())
73
->withPHIDs(array($service_phid))
74
->requireCapabilities(
75
array(
76
PhabricatorPolicyCapability::CAN_VIEW,
77
PhabricatorPolicyCapability::CAN_EDIT,
78
))
79
->executeOne();
80
if (!$service) {
81
throw new Exception(
82
pht(
83
'Service "%s" is unrecognized, restricted, or you do not have '.
84
'permission to edit it.',
85
$service_phid));
86
}
87
88
$this->setService($service);
89
90
return $this->newEditableObject();
91
}
92
93
protected function newObjectQuery() {
94
return id(new AlmanacBindingQuery())
95
->needProperties(true);
96
}
97
98
protected function getObjectCreateTitleText($object) {
99
return pht('Create Binding');
100
}
101
102
protected function getObjectCreateButtonText($object) {
103
return pht('Create Binding');
104
}
105
106
protected function getObjectEditTitleText($object) {
107
return pht('Edit Binding');
108
}
109
110
protected function getObjectEditShortText($object) {
111
return pht('Edit Binding');
112
}
113
114
protected function getObjectCreateShortText() {
115
return pht('Create Binding');
116
}
117
118
protected function getObjectName() {
119
return pht('Binding');
120
}
121
122
protected function getEditorURI() {
123
return '/almanac/binding/edit/';
124
}
125
126
protected function getObjectCreateCancelURI($object) {
127
return '/almanac/binding/';
128
}
129
130
protected function getObjectViewURI($object) {
131
return $object->getURI();
132
}
133
134
protected function buildCustomEditFields($object) {
135
return array(
136
id(new PhabricatorTextEditField())
137
->setKey('service')
138
->setLabel(pht('Service'))
139
->setIsFormField(false)
140
->setTransactionType(
141
AlmanacBindingServiceTransaction::TRANSACTIONTYPE)
142
->setDescription(pht('Service to create a binding for.'))
143
->setConduitDescription(pht('Select the service to bind.'))
144
->setConduitTypeDescription(pht('Service PHID.'))
145
->setValue($object->getServicePHID()),
146
id(new PhabricatorTextEditField())
147
->setKey('interface')
148
->setLabel(pht('Interface'))
149
->setIsFormField(false)
150
->setTransactionType(
151
AlmanacBindingInterfaceTransaction::TRANSACTIONTYPE)
152
->setDescription(pht('Interface to bind the service to.'))
153
->setConduitDescription(pht('Set the interface to bind.'))
154
->setConduitTypeDescription(pht('Interface PHID.'))
155
->setValue($object->getInterfacePHID()),
156
id(new PhabricatorBoolEditField())
157
->setKey('disabled')
158
->setLabel(pht('Disabled'))
159
->setIsFormField(false)
160
->setTransactionType(
161
AlmanacBindingDisableTransaction::TRANSACTIONTYPE)
162
->setDescription(pht('Disable or enable the binding.'))
163
->setConduitDescription(pht('Disable or enable the binding.'))
164
->setConduitTypeDescription(pht('True to disable the binding.'))
165
->setValue($object->getIsDisabled())
166
->setOptions(
167
pht('Enable Binding'),
168
pht('Disable Binding')),
169
);
170
}
171
172
}
173
174