[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * Base class for Differential fields with storage on the revision object
   5   * itself. This mostly wraps reading/writing field values to and from the
   6   * object.
   7   */
   8  abstract class DifferentialCoreCustomField
   9    extends DifferentialCustomField {
  10  
  11    private $value;
  12    private $fieldError;
  13  
  14    abstract protected function readValueFromRevision(
  15      DifferentialRevision $revision);
  16  
  17    protected function writeValueToRevision(
  18      DifferentialRevision $revision,
  19      $value) {
  20      throw new PhabricatorCustomFieldImplementationIncompleteException($this);
  21    }
  22  
  23    protected function isCoreFieldRequired() {
  24      return false;
  25    }
  26  
  27    protected function isCoreFieldValueEmpty($value) {
  28      if (is_array($value)) {
  29        return !$value;
  30      }
  31      return !strlen(trim($value));
  32    }
  33  
  34    protected function getCoreFieldRequiredErrorString() {
  35      throw new PhabricatorCustomFieldImplementationIncompleteException($this);
  36    }
  37  
  38    public function validateApplicationTransactions(
  39      PhabricatorApplicationTransactionEditor $editor,
  40      $type,
  41      array $xactions) {
  42  
  43      $this->setFieldError(null);
  44  
  45      $errors = parent::validateApplicationTransactions(
  46        $editor,
  47        $type,
  48        $xactions);
  49  
  50      $transaction = null;
  51      foreach ($xactions as $xaction) {
  52        $value = $xaction->getNewValue();
  53        if ($this->isCoreFieldRequired()) {
  54          if ($this->isCoreFieldValueEmpty($value)) {
  55            $error = new PhabricatorApplicationTransactionValidationError(
  56              $type,
  57              pht('Required'),
  58              $this->getCoreFieldRequiredErrorString(),
  59              $xaction);
  60            $error->setIsMissingFieldError(true);
  61            $errors[] = $error;
  62            $this->setFieldError(pht('Required'));
  63          }
  64        }
  65      }
  66  
  67      return $errors;
  68    }
  69  
  70    public function canDisableField() {
  71      return false;
  72    }
  73  
  74    public function shouldAppearInApplicationTransactions() {
  75      return true;
  76    }
  77  
  78    public function shouldAppearInEditView() {
  79      return true;
  80    }
  81  
  82    public function readValueFromObject(PhabricatorCustomFieldInterface $object) {
  83      if ($this->isCoreFieldRequired()) {
  84        $this->setFieldError(true);
  85      }
  86      $this->setValue($this->readValueFromRevision($object));
  87    }
  88  
  89    public function getOldValueForApplicationTransactions() {
  90      return $this->readValueFromRevision($this->getObject());
  91    }
  92  
  93    public function getNewValueForApplicationTransactions() {
  94      return $this->getValue();
  95    }
  96  
  97    public function applyApplicationTransactionInternalEffects(
  98      PhabricatorApplicationTransaction $xaction) {
  99      $this->writeValueToRevision($this->getObject(), $xaction->getNewValue());
 100    }
 101  
 102    public function setFieldError($field_error) {
 103      $this->fieldError = $field_error;
 104      return $this;
 105    }
 106  
 107    public function getFieldError() {
 108      return $this->fieldError;
 109    }
 110  
 111    public function setValue($value) {
 112      $this->value = $value;
 113      return $this;
 114    }
 115  
 116    public function getValue() {
 117      return $this->value;
 118    }
 119  
 120    public function readValueFromCommitMessage($value) {
 121      $this->setValue($value);
 122      return $this;
 123    }
 124  
 125    public function renderCommitMessageValue(array $handles) {
 126      return $this->getValue();
 127    }
 128  
 129    public function getConduitDictionaryValue() {
 130      return $this->getValue();
 131    }
 132  
 133  }


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