[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/differential/customfield/ -> DifferentialTitleField.php (source)

   1  <?php
   2  
   3  final class DifferentialTitleField
   4    extends DifferentialCoreCustomField {
   5  
   6    public function getFieldKey() {
   7      return 'differential:title';
   8    }
   9  
  10    public function getFieldKeyForConduit() {
  11      return 'title';
  12    }
  13  
  14    public function getFieldName() {
  15      return pht('Title');
  16    }
  17  
  18    public function getFieldDescription() {
  19      return pht('Stores the revision title.');
  20    }
  21  
  22    public static function getDefaultTitle() {
  23      return pht('<<Replace this line with your Revision Title>>');
  24    }
  25  
  26    protected function readValueFromRevision(
  27      DifferentialRevision $revision) {
  28      return $revision->getTitle();
  29    }
  30  
  31    protected function writeValueToRevision(
  32      DifferentialRevision $revision,
  33      $value) {
  34      $revision->setTitle($value);
  35    }
  36  
  37    protected function getCoreFieldRequiredErrorString() {
  38      return pht('You must choose a title for this revision.');
  39    }
  40  
  41    public function readValueFromRequest(AphrontRequest $request) {
  42      $this->setValue($request->getStr($this->getFieldKey()));
  43    }
  44  
  45    protected function isCoreFieldRequired() {
  46      return true;
  47    }
  48  
  49    public function renderEditControl(array $handles) {
  50      return id(new AphrontFormTextAreaControl())
  51        ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)
  52        ->setName($this->getFieldKey())
  53        ->setValue($this->getValue())
  54        ->setError($this->getFieldError())
  55        ->setLabel($this->getFieldName());
  56    }
  57  
  58    public function getApplicationTransactionTitle(
  59      PhabricatorApplicationTransaction $xaction) {
  60      $author_phid = $xaction->getAuthorPHID();
  61      $old = $xaction->getOldValue();
  62      $new = $xaction->getNewValue();
  63  
  64      if (strlen($old)) {
  65        return pht(
  66          '%s retitled this revision from "%s" to "%s".',
  67          $xaction->renderHandleLink($author_phid),
  68          $old,
  69          $new);
  70      } else {
  71        return pht(
  72          '%s created this revision.',
  73          $xaction->renderHandleLink($author_phid));
  74      }
  75    }
  76  
  77    public function getApplicationTransactionTitleForFeed(
  78      PhabricatorApplicationTransaction $xaction,
  79      PhabricatorFeedStory $story) {
  80  
  81      $object_phid = $xaction->getObjectPHID();
  82      $author_phid = $xaction->getAuthorPHID();
  83      $old = $xaction->getOldValue();
  84      $new = $xaction->getNewValue();
  85  
  86      if (strlen($old)) {
  87        return pht(
  88          '%s retitled %s, from "%s" to "%s".',
  89          $xaction->renderHandleLink($author_phid),
  90          $xaction->renderHandleLink($object_phid),
  91          $old,
  92          $new);
  93      } else {
  94        return pht(
  95          '%s created %s.',
  96          $xaction->renderHandleLink($author_phid),
  97          $xaction->renderHandleLink($object_phid));
  98      }
  99    }
 100  
 101    public function shouldAppearInCommitMessage() {
 102      return true;
 103    }
 104  
 105    public function shouldOverwriteWhenCommitMessageIsEdited() {
 106      return true;
 107    }
 108  
 109    public function validateCommitMessageValue($value) {
 110      if (!strlen($value)) {
 111        throw new DifferentialFieldValidationException(
 112          pht(
 113            'You must provide a revision title in the first line '.
 114            'of your commit message.'));
 115      }
 116  
 117      if (preg_match('/^<<.*>>$/', $value)) {
 118        throw new DifferentialFieldValidationException(
 119          pht(
 120            'Replace the line "%s" with a human-readable revision title which '.
 121            'describes the changes you are making.',
 122            self::getDefaultTitle()));
 123      }
 124    }
 125  
 126  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1