Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/legalpad/xaction/LegalpadDocumentTitleTransaction.php
13464 views
1
<?php
2
3
final class LegalpadDocumentTitleTransaction
4
extends LegalpadDocumentTransactionType {
5
6
const TRANSACTIONTYPE = 'title';
7
8
public function generateOldValue($object) {
9
return $object->getTitle();
10
}
11
12
public function applyInternalEffects($object, $value) {
13
$object->setTitle($value);
14
$body = $object->getDocumentBody();
15
$body->setTitle($value);
16
$object->attachDocumentBody($body);
17
}
18
19
public function getTitle() {
20
$old = $this->getOldValue();
21
22
if (!strlen($old)) {
23
return pht(
24
'%s created this document.',
25
$this->renderAuthor());
26
} else {
27
return pht(
28
'%s renamed this document from %s to %s.',
29
$this->renderAuthor(),
30
$this->renderOldValue(),
31
$this->renderNewValue());
32
}
33
}
34
35
public function getTitleForFeed() {
36
$old = $this->getOldValue();
37
38
if (!strlen($old)) {
39
return pht(
40
'%s created %s.',
41
$this->renderAuthor(),
42
$this->renderObject());
43
} else {
44
return pht(
45
'%s renamed %s from %s to %s.',
46
$this->renderAuthor(),
47
$this->renderObject(),
48
$this->renderOldValue(),
49
$this->renderNewValue());
50
}
51
}
52
53
public function validateTransactions($object, array $xactions) {
54
$errors = array();
55
56
if ($this->isEmptyTextTransaction($object->getTitle(), $xactions)) {
57
$errors[] = $this->newRequiredError(
58
pht('Documents must have a title.'));
59
}
60
61
$max_length = $object->getColumnMaximumByteLength('title');
62
foreach ($xactions as $xaction) {
63
$new_value = $xaction->getNewValue();
64
$new_length = strlen($new_value);
65
if ($new_length > $max_length) {
66
$errors[] = $this->newInvalidError(
67
pht('The title can be no longer than %s characters.',
68
new PhutilNumber($max_length)));
69
}
70
}
71
72
return $errors;
73
}
74
75
}
76
77