[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class DifferentialRepositoryField
   4    extends DifferentialCoreCustomField {
   5  
   6    public function getFieldKey() {
   7      return 'differential:repository';
   8    }
   9  
  10    public function getFieldName() {
  11      return pht('Repository');
  12    }
  13  
  14    public function getFieldDescription() {
  15      return pht('Associates a revision with a repository.');
  16    }
  17  
  18    protected function readValueFromRevision(
  19      DifferentialRevision $revision) {
  20      return $revision->getRepositoryPHID();
  21    }
  22  
  23    protected function writeValueToRevision(
  24      DifferentialRevision $revision,
  25      $value) {
  26      $revision->setRepositoryPHID($value);
  27    }
  28  
  29    public function readValueFromRequest(AphrontRequest $request) {
  30      $phids = $request->getArr($this->getFieldKey());
  31      $first = head($phids);
  32      $this->setValue(nonempty($first, null));
  33    }
  34  
  35    public function getRequiredHandlePHIDsForEdit() {
  36      $phids = array();
  37      if ($this->getValue()) {
  38        $phids[] = $this->getValue();
  39      }
  40      return $phids;
  41    }
  42  
  43    public function renderEditControl(array $handles) {
  44      if ($this->getValue()) {
  45        $control_value = array_select_keys($handles, array($this->getValue()));
  46      } else {
  47        $control_value = array();
  48      }
  49  
  50      return id(new AphrontFormTokenizerControl())
  51        ->setName($this->getFieldKey())
  52        ->setDatasource(new DiffusionRepositoryDatasource())
  53        ->setValue($control_value)
  54        ->setError($this->getFieldError())
  55        ->setLabel($this->getFieldName())
  56        ->setLimit(1);
  57    }
  58  
  59    public function getApplicationTransactionRequiredHandlePHIDs(
  60      PhabricatorApplicationTransaction $xaction) {
  61  
  62      $old = $xaction->getOldValue();
  63      $new = $xaction->getNewValue();
  64  
  65      $phids = array();
  66      if ($old) {
  67        $phids[] = $old;
  68      }
  69      if ($new) {
  70        $phids[] = $new;
  71      }
  72  
  73      return $phids;
  74    }
  75  
  76    public function getApplicationTransactionTitle(
  77      PhabricatorApplicationTransaction $xaction) {
  78      $author_phid = $xaction->getAuthorPHID();
  79      $old = $xaction->getOldValue();
  80      $new = $xaction->getNewValue();
  81  
  82      if ($old && $new) {
  83        return pht(
  84          '%s changed the repository for this revision from %s to %s.',
  85          $xaction->renderHandleLink($author_phid),
  86          $xaction->renderHandleLink($old),
  87          $xaction->renderHandleLink($new));
  88      } else if ($new) {
  89        return pht(
  90          '%s set the repository for this revision to %s.',
  91          $xaction->renderHandleLink($author_phid),
  92          $xaction->renderHandleLink($new));
  93      } else {
  94        return pht(
  95          '%s removed %s as the repository for this revision.',
  96          $xaction->renderHandleLink($author_phid),
  97          $xaction->renderHandleLink($old));
  98      }
  99    }
 100  
 101    public function getApplicationTransactionTitleForFeed(
 102      PhabricatorApplicationTransaction $xaction,
 103      PhabricatorFeedStory $story) {
 104  
 105      $object_phid = $xaction->getObjectPHID();
 106      $author_phid = $xaction->getAuthorPHID();
 107      $old = $xaction->getOldValue();
 108      $new = $xaction->getNewValue();
 109  
 110      if ($old && $new) {
 111        return pht(
 112          '%s updated the repository for %s from %s to %s.',
 113          $xaction->renderHandleLink($author_phid),
 114          $xaction->renderHandleLink($object_phid),
 115          $xaction->renderHandleLink($old),
 116          $xaction->renderHandleLink($new));
 117      } else if ($new) {
 118        return pht(
 119          '%s set the repository for %s to %s.',
 120          $xaction->renderHandleLink($author_phid),
 121          $xaction->renderHandleLink($object_phid),
 122          $xaction->renderHandleLink($new));
 123      } else {
 124        return pht(
 125          '%s removed the repository for %s. (Repository was %s.)',
 126          $xaction->renderHandleLink($author_phid),
 127          $xaction->renderHandleLink($object_phid),
 128          $xaction->renderHandleLink($old));
 129      }
 130    }
 131  
 132    public function shouldAppearInPropertyView() {
 133      return true;
 134    }
 135  
 136    public function renderPropertyViewLabel() {
 137      return $this->getFieldName();
 138    }
 139  
 140    public function getRequiredHandlePHIDsForPropertyView() {
 141      $repository_phid = $this->getObject()->getRepositoryPHID();
 142      if ($repository_phid) {
 143        return array($repository_phid);
 144      }
 145      return array();
 146    }
 147  
 148    public function renderPropertyViewValue(array $handles) {
 149      return $this->renderHandleList($handles);
 150    }
 151  
 152    public function shouldAppearInTransactionMail() {
 153      return true;
 154    }
 155  
 156    public function updateTransactionMailBody(
 157      PhabricatorMetaMTAMailBody $body,
 158      PhabricatorApplicationTransactionEditor $editor,
 159      array $xactions) {
 160  
 161      $repository = $this->getObject()->getRepository();
 162      if ($repository === null) {
 163        return;
 164      }
 165  
 166      $body->addTextSection(pht('REPOSITORY'),
 167        $repository->getMonogram().' '.$repository->getName());
 168    }
 169  
 170  }


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