@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 122 lines 3.0 kB view raw
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 */ 8abstract class DifferentialCoreCustomField 9 extends DifferentialCustomField { 10 11 private $value; 12 private $fieldError; 13 private $fieldParser; 14 15 abstract protected function readValueFromRevision( 16 DifferentialRevision $revision); 17 18 protected function writeValueToRevision( 19 DifferentialRevision $revision, 20 $value) { 21 throw new PhabricatorCustomFieldImplementationIncompleteException($this); 22 } 23 24 protected function isCoreFieldRequired() { 25 return false; 26 } 27 28 protected function isCoreFieldValueEmpty($value) { 29 if (is_array($value)) { 30 return !$value; 31 } 32 return !strlen(trim($value)); 33 } 34 35 protected function getCoreFieldRequiredErrorString() { 36 throw new PhabricatorCustomFieldImplementationIncompleteException($this); 37 } 38 39 public function validateApplicationTransactions( 40 PhabricatorApplicationTransactionEditor $editor, 41 $type, 42 array $xactions) { 43 44 $this->setFieldError(null); 45 46 $errors = parent::validateApplicationTransactions( 47 $editor, 48 $type, 49 $xactions); 50 51 $transaction = null; 52 foreach ($xactions as $xaction) { 53 $value = $xaction->getNewValue(); 54 if ($this->isCoreFieldRequired()) { 55 if ($this->isCoreFieldValueEmpty($value)) { 56 $error = new PhabricatorApplicationTransactionValidationError( 57 $type, 58 pht('Required'), 59 $this->getCoreFieldRequiredErrorString(), 60 $xaction); 61 $error->setIsMissingFieldError(true); 62 $errors[] = $error; 63 $this->setFieldError(pht('Required')); 64 continue; 65 } 66 } 67 } 68 69 return $errors; 70 } 71 72 public function canDisableField() { 73 return false; 74 } 75 76 public function shouldAppearInApplicationTransactions() { 77 return true; 78 } 79 80 public function readValueFromObject(PhabricatorCustomFieldInterface $object) { 81 if ($this->isCoreFieldRequired()) { 82 $this->setFieldError(true); 83 } 84 $this->setValue($this->readValueFromRevision($object)); 85 } 86 87 public function getOldValueForApplicationTransactions() { 88 return $this->readValueFromRevision($this->getObject()); 89 } 90 91 public function getNewValueForApplicationTransactions() { 92 return $this->getValue(); 93 } 94 95 public function applyApplicationTransactionInternalEffects( 96 PhabricatorApplicationTransaction $xaction) { 97 $this->writeValueToRevision($this->getObject(), $xaction->getNewValue()); 98 } 99 100 public function setFieldError($field_error) { 101 $this->fieldError = $field_error; 102 return $this; 103 } 104 105 public function getFieldError() { 106 return $this->fieldError; 107 } 108 109 public function setValue($value) { 110 $this->value = $value; 111 return $this; 112 } 113 114 public function getValue() { 115 return $this->value; 116 } 117 118 public function getConduitDictionaryValue() { 119 return $this->getValue(); 120 } 121 122}