Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/maniphest/xaction/ManiphestTaskTitleTransaction.php
12256 views
1
<?php
2
3
final class ManiphestTaskTitleTransaction
4
extends ManiphestTaskTransactionType {
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
}
15
16
public function getActionStrength() {
17
return 140;
18
}
19
20
public function getActionName() {
21
$old = $this->getOldValue();
22
23
if (!strlen($old)) {
24
return pht('Created');
25
}
26
27
return pht('Retitled');
28
}
29
30
public function getTitle() {
31
$old = $this->getOldValue();
32
33
if (!strlen($old)) {
34
return pht(
35
'%s created this task.',
36
$this->renderAuthor());
37
}
38
39
return pht(
40
'%s renamed this task from %s to %s.',
41
$this->renderAuthor(),
42
$this->renderOldValue(),
43
$this->renderNewValue());
44
45
}
46
47
public function getTitleForFeed() {
48
$old = $this->getOldValue();
49
if ($old === null) {
50
return pht(
51
'%s created %s.',
52
$this->renderAuthor(),
53
$this->renderObject());
54
}
55
56
return pht(
57
'%s renamed %s from %s to %s.',
58
$this->renderAuthor(),
59
$this->renderObject(),
60
$this->renderOldValue(),
61
$this->renderNewValue());
62
}
63
64
public function validateTransactions($object, array $xactions) {
65
$errors = array();
66
67
// If the user is acting via "Bulk Edit" or another workflow which
68
// continues on missing fields, they may be applying a transaction which
69
// removes the task title. Mark these transactions as invalid first,
70
// then flag the missing field error if we don't find any more specific
71
// problems.
72
73
foreach ($xactions as $xaction) {
74
$new = $xaction->getNewValue();
75
if (!strlen($new)) {
76
$errors[] = $this->newInvalidError(
77
pht('Tasks must have a title.'),
78
$xaction);
79
continue;
80
}
81
}
82
83
if (!$errors) {
84
if ($this->isEmptyTextTransaction($object->getTitle(), $xactions)) {
85
$errors[] = $this->newRequiredError(
86
pht('Tasks must have a title.'));
87
}
88
}
89
90
return $errors;
91
}
92
93
public function getTransactionTypeForConduit($xaction) {
94
return 'title';
95
}
96
97
public function getFieldValuesForConduit($xaction, $data) {
98
return array(
99
'old' => $xaction->getOldValue(),
100
'new' => $xaction->getNewValue(),
101
);
102
}
103
104
}
105
106