3 final class PhabricatorFileAltTextTransaction
4 extends PhabricatorFileTransactionType
{
6 const TRANSACTIONTYPE
= 'file:alt';
8 public function generateOldValue($object) {
9 return $object->getCustomAltText();
12 public function generateNewValue($object, $value) {
13 $value = phutil_string_cast($value);
15 if (!strlen($value)) {
22 public function applyInternalEffects($object, $value) {
23 $object->setCustomAltText($value);
26 public function getTitle() {
27 $old_value = $this->getOldValue();
28 $new_value = $this->getNewValue();
30 if (!strlen($old_value)) {
32 '%s set the alternate text for this file to %s.',
33 $this->renderAuthor(),
34 $this->renderNewValue());
35 } else if (!strlen($new_value)) {
37 '%s removed the alternate text for this file (was %s).',
38 $this->renderAuthor(),
39 $this->renderOldValue());
42 '%s changed the alternate text for this file from %s to %s.',
43 $this->renderAuthor(),
44 $this->renderOldValue(),
45 $this->renderNewValue());
49 public function getTitleForFeed() {
50 $old_value = $this->getOldValue();
51 $new_value = $this->getNewValue();
53 if (!strlen($old_value)) {
55 '%s set the alternate text for %s to %s.',
56 $this->renderAuthor(),
57 $this->renderObject(),
58 $this->renderNewValue());
59 } else if (!strlen($new_value)) {
61 '%s removed the alternate text for %s (was %s).',
62 $this->renderAuthor(),
63 $this->renderObject(),
64 $this->renderOldValue());
67 '%s changed the alternate text for %s from %s to %s.',
68 $this->renderAuthor(),
69 $this->renderObject(),
70 $this->renderOldValue(),
71 $this->renderNewValue());
75 public function validateTransactions($object, array $xactions) {
79 foreach ($xactions as $xaction) {
80 $new_value = $xaction->getNewValue();
82 $new_length = strlen($new_value);
83 if ($new_length > $max_length) {
84 $errors[] = $this->newInvalidError(
86 'File alternate text must not be longer than %s character(s).',
87 new PhutilNumber($max_length)));