Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/legalpad/editor/LegalpadDocumentEditEngine.php
13459 views
1
<?php
2
3
final class LegalpadDocumentEditEngine
4
extends PhabricatorEditEngine {
5
6
const ENGINECONST = 'legalpad.document';
7
8
public function getEngineName() {
9
return pht('Legalpad');
10
}
11
12
public function getEngineApplicationClass() {
13
return 'PhabricatorLegalpadApplication';
14
}
15
16
public function getSummaryHeader() {
17
return pht('Configure Legalpad Forms');
18
}
19
20
public function getSummaryText() {
21
return pht('Configure creation and editing documents in Legalpad.');
22
}
23
24
public function isEngineConfigurable() {
25
return false;
26
}
27
28
protected function newEditableObject() {
29
$viewer = $this->getViewer();
30
31
$document = LegalpadDocument::initializeNewDocument($viewer);
32
$body = id(new LegalpadDocumentBody())
33
->setCreatorPHID($viewer->getPHID());
34
$document->attachDocumentBody($body);
35
$document->setDocumentBodyPHID(PhabricatorPHIDConstants::PHID_VOID);
36
37
return $document;
38
}
39
40
protected function newObjectQuery() {
41
return id(new LegalpadDocumentQuery())
42
->needDocumentBodies(true);
43
}
44
45
protected function getObjectCreateTitleText($object) {
46
return pht('Create New Document');
47
}
48
49
protected function getObjectEditTitleText($object) {
50
$body = $object->getDocumentBody();
51
$title = $body->getTitle();
52
return pht('Edit Document: %s', $title);
53
}
54
55
protected function getObjectEditShortText($object) {
56
$body = $object->getDocumentBody();
57
return $body->getTitle();
58
}
59
60
protected function getObjectCreateShortText() {
61
return pht('Create Document');
62
}
63
64
protected function getObjectName() {
65
return pht('Document');
66
}
67
68
protected function getObjectCreateCancelURI($object) {
69
return $this->getApplication()->getApplicationURI('/');
70
}
71
72
protected function getEditorURI() {
73
return $this->getApplication()->getApplicationURI('edit/');
74
}
75
76
protected function getObjectViewURI($object) {
77
$id = $object->getID();
78
return $this->getApplication()->getApplicationURI('view/'.$id.'/');
79
}
80
81
82
protected function getCreateNewObjectPolicy() {
83
return $this->getApplication()->getPolicy(
84
LegalpadCreateDocumentsCapability::CAPABILITY);
85
}
86
87
protected function buildCustomEditFields($object) {
88
$viewer = $this->getViewer();
89
90
$body = $object->getDocumentBody();
91
$document_body = $body->getText();
92
93
$is_create = $this->getIsCreate();
94
$is_admin = $viewer->getIsAdmin();
95
96
$fields = array();
97
$fields[] =
98
id(new PhabricatorTextEditField())
99
->setKey('title')
100
->setLabel(pht('Title'))
101
->setDescription(pht('Document Title.'))
102
->setConduitTypeDescription(pht('New document title.'))
103
->setValue($object->getTitle())
104
->setIsRequired(true)
105
->setTransactionType(
106
LegalpadDocumentTitleTransaction::TRANSACTIONTYPE);
107
108
if ($is_create) {
109
$fields[] =
110
id(new PhabricatorSelectEditField())
111
->setKey('signatureType')
112
->setLabel(pht('Who Should Sign?'))
113
->setDescription(pht('Type of signature required'))
114
->setConduitTypeDescription(pht('New document signature type.'))
115
->setValue($object->getSignatureType())
116
->setOptions(LegalpadDocument::getSignatureTypeMap())
117
->setTransactionType(
118
LegalpadDocumentSignatureTypeTransaction::TRANSACTIONTYPE);
119
$show_require = true;
120
} else {
121
$fields[] = id(new PhabricatorStaticEditField())
122
->setLabel(pht('Who Should Sign?'))
123
->setValue($object->getSignatureTypeName());
124
$individual = LegalpadDocument::SIGNATURE_TYPE_INDIVIDUAL;
125
$show_require = $object->getSignatureType() == $individual;
126
}
127
128
if ($show_require && $is_admin) {
129
$fields[] =
130
id(new PhabricatorBoolEditField())
131
->setKey('requireSignature')
132
->setOptions(
133
pht('No Signature Required'),
134
pht('Signature Required to Log In'))
135
->setAsCheckbox(true)
136
->setTransactionType(
137
LegalpadDocumentRequireSignatureTransaction::TRANSACTIONTYPE)
138
->setDescription(pht('Marks this document as required signing.'))
139
->setConduitDescription(
140
pht('Marks this document as required signing.'))
141
->setValue($object->getRequireSignature());
142
}
143
144
$fields[] =
145
id(new PhabricatorRemarkupEditField())
146
->setKey('preamble')
147
->setLabel(pht('Preamble'))
148
->setDescription(pht('The preamble of the document.'))
149
->setConduitTypeDescription(pht('New document preamble.'))
150
->setValue($object->getPreamble())
151
->setTransactionType(
152
LegalpadDocumentPreambleTransaction::TRANSACTIONTYPE);
153
154
$fields[] =
155
id(new PhabricatorRemarkupEditField())
156
->setKey('text')
157
->setLabel(pht('Document Body'))
158
->setDescription(pht('The body of text of the document.'))
159
->setConduitTypeDescription(pht('New document body.'))
160
->setValue($document_body)
161
->setIsRequired(true)
162
->setTransactionType(
163
LegalpadDocumentTextTransaction::TRANSACTIONTYPE);
164
165
return $fields;
166
167
}
168
169
}
170
171