Path: blob/master/src/applications/legalpad/xaction/LegalpadDocumentTitleTransaction.php
13464 views
<?php12final class LegalpadDocumentTitleTransaction3extends LegalpadDocumentTransactionType {45const TRANSACTIONTYPE = 'title';67public function generateOldValue($object) {8return $object->getTitle();9}1011public function applyInternalEffects($object, $value) {12$object->setTitle($value);13$body = $object->getDocumentBody();14$body->setTitle($value);15$object->attachDocumentBody($body);16}1718public function getTitle() {19$old = $this->getOldValue();2021if (!strlen($old)) {22return pht(23'%s created this document.',24$this->renderAuthor());25} else {26return pht(27'%s renamed this document from %s to %s.',28$this->renderAuthor(),29$this->renderOldValue(),30$this->renderNewValue());31}32}3334public function getTitleForFeed() {35$old = $this->getOldValue();3637if (!strlen($old)) {38return pht(39'%s created %s.',40$this->renderAuthor(),41$this->renderObject());42} else {43return pht(44'%s renamed %s from %s to %s.',45$this->renderAuthor(),46$this->renderObject(),47$this->renderOldValue(),48$this->renderNewValue());49}50}5152public function validateTransactions($object, array $xactions) {53$errors = array();5455if ($this->isEmptyTextTransaction($object->getTitle(), $xactions)) {56$errors[] = $this->newRequiredError(57pht('Documents must have a title.'));58}5960$max_length = $object->getColumnMaximumByteLength('title');61foreach ($xactions as $xaction) {62$new_value = $xaction->getNewValue();63$new_length = strlen($new_value);64if ($new_length > $max_length) {65$errors[] = $this->newInvalidError(66pht('The title can be no longer than %s characters.',67new PhutilNumber($max_length)));68}69}7071return $errors;72}7374}757677