Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/files/xaction/PhabricatorFileAltTextTransaction.php
12241 views
1
<?php
2
3
final class PhabricatorFileAltTextTransaction
4
extends PhabricatorFileTransactionType {
5
6
const TRANSACTIONTYPE = 'file:alt';
7
8
public function generateOldValue($object) {
9
return $object->getCustomAltText();
10
}
11
12
public function generateNewValue($object, $value) {
13
$value = phutil_string_cast($value);
14
15
if (!strlen($value)) {
16
$value = null;
17
}
18
19
return $value;
20
}
21
22
public function applyInternalEffects($object, $value) {
23
$object->setCustomAltText($value);
24
}
25
26
public function getTitle() {
27
$old_value = $this->getOldValue();
28
$new_value = $this->getNewValue();
29
30
if ($old_value == null || !strlen($old_value)) {
31
return pht(
32
'%s set the alternate text for this file to %s.',
33
$this->renderAuthor(),
34
$this->renderNewValue());
35
} else if ($new_value === null || !strlen($new_value)) {
36
return pht(
37
'%s removed the alternate text for this file (was %s).',
38
$this->renderAuthor(),
39
$this->renderOldValue());
40
} else {
41
return pht(
42
'%s changed the alternate text for this file from %s to %s.',
43
$this->renderAuthor(),
44
$this->renderOldValue(),
45
$this->renderNewValue());
46
}
47
}
48
49
public function getTitleForFeed() {
50
$old_value = $this->getOldValue();
51
$new_value = $this->getNewValue();
52
53
if ($old_value === null || !strlen($old_value)) {
54
return pht(
55
'%s set the alternate text for %s to %s.',
56
$this->renderAuthor(),
57
$this->renderObject(),
58
$this->renderNewValue());
59
} else if ($new_value === null || !strlen($new_value)) {
60
return pht(
61
'%s removed the alternate text for %s (was %s).',
62
$this->renderAuthor(),
63
$this->renderObject(),
64
$this->renderOldValue());
65
} else {
66
return pht(
67
'%s changed the alternate text for %s from %s to %s.',
68
$this->renderAuthor(),
69
$this->renderObject(),
70
$this->renderOldValue(),
71
$this->renderNewValue());
72
}
73
}
74
75
public function validateTransactions($object, array $xactions) {
76
$errors = array();
77
78
$max_length = 1024;
79
foreach ($xactions as $xaction) {
80
$new_value = $xaction->getNewValue();
81
82
$new_length = strlen($new_value);
83
if ($new_length > $max_length) {
84
$errors[] = $this->newInvalidError(
85
pht(
86
'File alternate text must not be longer than %s character(s).',
87
new PhutilNumber($max_length)));
88
}
89
}
90
91
return $errors;
92
}
93
94
}
95
96