Path: blob/master/src/applications/differential/customfield/DifferentialCoreCustomField.php
12256 views
<?php12/**3* Base class for Differential fields with storage on the revision object4* itself. This mostly wraps reading/writing field values to and from the5* object.6*/7abstract class DifferentialCoreCustomField8extends DifferentialCustomField {910private $value;11private $fieldError;12private $fieldParser;1314abstract protected function readValueFromRevision(15DifferentialRevision $revision);1617protected function writeValueToRevision(18DifferentialRevision $revision,19$value) {20throw new PhabricatorCustomFieldImplementationIncompleteException($this);21}2223protected function isCoreFieldRequired() {24return false;25}2627protected function isCoreFieldValueEmpty($value) {28if (is_array($value)) {29return !$value;30}31return !strlen(trim($value));32}3334protected function getCoreFieldRequiredErrorString() {35throw new PhabricatorCustomFieldImplementationIncompleteException($this);36}3738public function validateApplicationTransactions(39PhabricatorApplicationTransactionEditor $editor,40$type,41array $xactions) {4243$this->setFieldError(null);4445$errors = parent::validateApplicationTransactions(46$editor,47$type,48$xactions);4950$transaction = null;51foreach ($xactions as $xaction) {52$value = $xaction->getNewValue();53if ($this->isCoreFieldRequired()) {54if ($this->isCoreFieldValueEmpty($value)) {55$error = new PhabricatorApplicationTransactionValidationError(56$type,57pht('Required'),58$this->getCoreFieldRequiredErrorString(),59$xaction);60$error->setIsMissingFieldError(true);61$errors[] = $error;62$this->setFieldError(pht('Required'));63continue;64}65}66}6768return $errors;69}7071public function canDisableField() {72return false;73}7475public function shouldAppearInApplicationTransactions() {76return true;77}7879public function readValueFromObject(PhabricatorCustomFieldInterface $object) {80if ($this->isCoreFieldRequired()) {81$this->setFieldError(true);82}83$this->setValue($this->readValueFromRevision($object));84}8586public function getOldValueForApplicationTransactions() {87return $this->readValueFromRevision($this->getObject());88}8990public function getNewValueForApplicationTransactions() {91return $this->getValue();92}9394public function applyApplicationTransactionInternalEffects(95PhabricatorApplicationTransaction $xaction) {96$this->writeValueToRevision($this->getObject(), $xaction->getNewValue());97}9899public function setFieldError($field_error) {100$this->fieldError = $field_error;101return $this;102}103104public function getFieldError() {105return $this->fieldError;106}107108public function setValue($value) {109$this->value = $value;110return $this;111}112113public function getValue() {114return $this->value;115}116117public function getConduitDictionaryValue() {118return $this->getValue();119}120121}122123124